2017-03-03 101 views
0

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

**添加**兩行或**插入**兩行? –

+0

@加里的學生對不起,應該插入兩行。 – Anthony

回答

1

如果您正打算插入兩行(見Gary的評論)時,你可以從這個快速變化:

MyRange.Rows(iCounter).EntireRow.Insert 

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

謝謝!完美的作品。 – Anthony

相關問題