在 Excel VBA 中的原始表的每行之间添加 10 行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19839277/
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
Adding 10 rows between each row in my original table in Excel VBA
提问by E.Escoba
I have a table with data where I want to insert exactly 20 rows between each row of my original table. I have tried running nested for loops to add each row per loop and to hop onto the next "original" row on my table to add another 20 rows below it. However, this takes forever since I have over 2000 rows on my spreadsheet. Is there any other way to do this? Any vba code I could use for this?
我有一个包含数据的表,我想在原始表的每行之间插入 20 行。我试过运行嵌套 for 循环来添加每个循环的每一行,并跳到我表上的下一个“原始”行以在它下面添加另外 20 行。但是,这需要很长时间,因为我的电子表格上有 2000 多行。有没有其他方法可以做到这一点?我可以使用任何vba代码吗?
回答by Portland Runner
Try this:
尝试这个:
Sub AddRows()
ScreenUpdating = False
With ActiveSheet
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Dim AddRows As Integer: AddRows = 10
Dim i As Integer: i = lastrow
Do While i <> 1
Rows(i & ":" & i + AddRows - 1).Insert
i = i - 1
Loop
ScreenUpdating = True
End Sub
回答by Loomah
basis of a solution (ie change upper and lower bounds of loop and or add them programatically)
解决方案的基础(即更改循环的上限和下限和或以编程方式添加它们)
For i = 10 To 1 Step -1
Rows(i + 1 & ":" & i + 10).Insert
Next