inserting multiple rows after nth rows

edgrilufi

New Member
Joined
Oct 4, 2011
Messages
1
I am trying to insert 6 blank rows after every 6 rows of data using a macro. I have this code but it just inserts 1 blank row every 6 rows of data.

Sub Insert7thRow()

Dim rCell As Range, l As Long
For Each rCell In Selection
l = l + 1
If l Mod 7 = 0 Then rCell.EntireRow.Insert
Next rCell

End Sub

Can someone help me?
thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
data is from A1 down number of rows with no column headers

sample data as follows
Excel Workbook
A
11
22
33
44
55
66
77
88
99
1010
1111
1212
1313
1414
1515
1616
1717
1818
1919
2020
2121
2222
2323
2424
2525
2626
2727
2828
2929
3030
3131
3232
3333
3434
3535
3636
3737
3838
3939
4040
4141
4242
4343
4444
Sheet1


try this macro test which is slight modification of yours

Code:
Sub test()
Dim j As Long

For j = Range("a1").End(xlDown).Row To 1 Step -1
If j Mod 7 = 0 Then Range(Cells(j, 1), Cells(j + 5, 1)).EntireRow.Insert
Next j
End Sub
Code:
Sub undo()
Range("A1").EntireColumn.Sort key1:=Range("A1"), header:=xlNo
End Sub
modify the macros to suit you
 
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,640
Members
448,974
Latest member
DumbFinanceBro

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top