如何更改以下代码以添加2行?
Sub AddRows()
Dim MyRange As Range
Dim iCounter As Long
Dim LastRow As Long
With ThisWorkbook.Worksheets("Numbers")
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
Set MyRange = Range("A2:A" & LastRow)
For iCounter = MyRange.Rows.Count To 2 Step -1
'Insert blank row,
MyRange.Rows(iCounter).EntireRow.Insert
Next iCounter
End With
End Sub
答案 0 :(得分:1)
如果您打算插入两行(请参阅Gary的评论),您可以对此进行快速更改:
MyRange.Rows(iCounter).EntireRow.Insert
到
MyRange.Rows(iCounter).Resize(2,1).EntireRow.Insert