将行插入指定列

Insert rows into the specified columns

我有个小问题。我想仅在 A - D 列中插入行。如果此代码与上限值对齐,则此代码会插入一个新行。

Dim z     As Integer
Dim intLR As Integer

intLR = Range("A5536").End(xlUp).Row

For z = intLR To 2 Step -1
  If Cells(z, 1).Value <> Cells(z - 1, 1).Value Then
    Cells(z, 1).EntireRow.Insert
  Else

  End If
Next z

您应该能够使用 .Insert Method,传入 xlDown 来向下移动行。

下面只会在 A:D 列中插入新单元格。

Sub insertRow()
    Dim z As Integer, intLR As Integer
    intLR = Range("A5536").End(xlUp).Row

    For z = intLR To 2 Step -1
        If Cells(z, 1).Value <> Cells(z - 1, 1).Value Then
            Range(Cells(z, 1), Cells(z, 4)).Insert xlDown
        End If
    Next z
End Sub