根据单元格值插入复制的行

时间:2013-05-13 01:13:50

标签: excel excel-vba insert copy vba

下面的vba代码(从here修改)将在E列中任何值为“0”的行上方插入一个空行而不是插入一个空行,是否有办法复制用“0”行并将其插入上方?可以修改此vba代码来执行此操作吗?

Sub BlankLine()

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

        Col = "E"
        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) = "0" Then
.Cells(R, Col).EntireRow.Insert Shift:=xlDown
End If
Next R
End With
Application.ScreenUpdating = True

End Sub

1 个答案:

答案 0 :(得分:2)

只需添加此行

即可
.Cells(R, Col).EntireRow.Copy

.Insert行之前

相关问题