我需要有一个工作表根据K列中是否有文本数据自动插入一行

时间:2017-03-14 14:28:01

标签: excel excel-2016

这是我尝试过的。它可以工作,但不会自动工作。您必须运行宏才能使其工作。我需要它来输入数据。

Sub BlankLine()

    Dim Col As Variant
    Dim BlankRows As Long
    Dim LastRow As Long
    Dim R As Long
    Dim StartRow As Long

    Col = "K"
    StartRow = 1
    BlankRows = 1

        LastRow = Cells(Rows.Count, Col).End(xlUp).Row

        Application.ScreenUpdating = False

        With ActiveSheet
For R = LastRow To StartRow + 1 Step -1
If .Cells(R, Col) <> "" Then
.Cells(R + 1, Col).EntireRow.Insert Shift:=xlDown
End If
Next R
End With
Application.ScreenUpdating = True

End Sub

0 个答案:

没有答案