[英]Inserting a blank row after each row in vba for excel
I'm using the following code: 我正在使用以下代码:
Sub del_row()
Dim r As Long, y As Long
y = Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp).Row
For r = 2 To y Step 2
Rows(r).Insert Shift:=xlDown
Next r
End Sub
This works, but stops at row 1020 and I'm not sure why. 这行得通,但停在1020行,我不确定为什么。 Is there a way I can modify this to continue until there is no more data?
有没有办法我可以修改它以继续直到没有更多数据?
If you are inserting or deleting rows, work from the bottom up. 如果要插入或删除行,请从下至上进行操作。
Sub del_row()
Dim r As Long, y As Long
y = Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp).Row
For r = y To 2 Step -1 '<~~ this is the magic
Sheet1.cells(r, 1).entirerow.Insert Shift:=xlDown
Next r
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.