Insert multiple rown at each change in data

lewis_green

New Member
Joined
Aug 20, 2007
Messages
10
Hi guys. I'm looking for a way to insert 5 blank rows between each change in data in Column B of my spreadsheet.

Currently I am using the following formula which inserts one row, but I have found nothing anywhere for a code that enters more than one row.


Sub MacroChangeindata()
'
' MacroChangeindata Macro
'
'Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(lRow, "A") <> Cells(lRow - 1, "A") Then Rows(lRow).EntireRow.Insert

Next lRow
End Sub

Any help would be appreciated!

Thanks
Lewis
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Hi. Try this

Rich (BB code):
Sub MacroChangeindata()
'
' MacroChangeindata Macro
'
'Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(lRow, "A") <> Cells(lRow - 1, "A") Then Rows(lRow).Resize(5).Insert

Next lRow
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,738
Messages
5,638,093
Members
417,005
Latest member
soso2727

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
Top