首页 文章

根据单元格值excel宏在下面插入行

提问于
浏览
0

嗨,我是一个完全新手,但渴望学习 . 我在这个论坛找到了一个宏Insert copied row based on cell value . 下面的宏在E列中的值为"0"的任何行上方插入一个空行,它几乎可以帮助我 . 而不是在行上方出现空行我需要它出现在下面 . 可以有人帮助我吗?宏代码是:

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

2 回答

  • 3

    编辑以下行:

    .Cells(R,Col).EntireRow.Insert Shift:= xlDown

    至:

    .Cells(R 1,Col).EntireRow.Insert Shift:= xlDown

  • 1

    与您有关的问题,修改原始代码中的一行:而不是:

    .Cells(R, Col).EntireRow.Insert Shift:=xlDown
    

    使用这个:

    .Cells(R, Col).EntireRow.Insert Shift:=xlUp
    

    RGDS,

相关问题