【问题标题】:Insert row below based on cell value根据单元格值在下面插入行
【发布时间】:2019-12-14 16:20:16
【问题描述】:

我在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

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    编辑以下行:

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

    到:

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

    【讨论】:

      【解决方案2】:

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

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

      使用这个:

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

      Rgds,

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多