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,081,767
Messages
5,361,164
Members
400,617
Latest member
barron1

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top