我有一个小问题。我想只在 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
关于vba - 将行插入指定的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31960139/