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
 

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824
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
 

Forum statistics

Threads
1,085,855
Messages
5,386,376
Members
401,996
Latest member
mg07p929

Some videos you may like

This Week's Hot Topics

Top