在 VBA Excel 中插入行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19715293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:05:16 来源:igfitidea点击:
Inserting rows in VBA Excel
提问by user20159
does anyone know how to insert 4 rows after each row, from row 2 to row 5? Of course using Excel VBA. I attach a picture to explain it better.
有谁知道如何在每行后插入 4 行,从第 2 行到第 5 行?当然使用Excel VBA。我附上一张图片来更好地解释它。
Any hints will be really appreciated. Regards!
任何提示将不胜感激。问候!
回答by Santosh
Try below code
试试下面的代码
Sub InsertRow()
Dim lastRow As Long
lastRow = Range("A" & Rows.Count).End(xlUp).Row
For i = lastRow To 3 Step -1
Cells(i, 1).Resize(4).Insert Shift:=xlDown
Next
End Sub
回答by Mad Dog Tannen
I recorded a Macro inserting a row. The code that came out was this.
我录制了一个插入一行的宏。出来的代码是这样的。
Sub Macro1()
'
' Macro1 Macro
'
'
Rows("2:5").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End Sub