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?
Asked
Active
Viewed 8,743 times
0
-
have you tried anything so far? – Mureinik Nov 07 '13 at 15:22
-
1Could you post the code you have been using until now? – Netloh Nov 07 '13 at 15:23
-
`Screenupdating=false` at the beginning of your loop will speed this type of process up significantly. – Automate This Nov 07 '13 at 15:27
2 Answers
3
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

Automate This
- 30,726
- 11
- 60
- 82
0
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

chris neilsen
- 52,446
- 10
- 84
- 123

Loomah
- 1
-
should be "i+20" and i need to look at how formatting (or mark up) works on this site before i come back!! – Loomah Nov 07 '13 at 15:43