如何更改以下代码以添加两行?

时间:2017-03-03 18:14:22

标签: excel vba

如何更改以下代码以添加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

1 个答案:

答案 0 :(得分:1)

如果您打算插入两行(请参阅Gary的评论),您可以对此进行快速更改:

MyRange.Rows(iCounter).EntireRow.Insert

MyRange.Rows(iCounter).Resize(2,1).EntireRow.Insert