Insert blank rows when field value changes

Rackette

New Member
Joined
Jul 2, 2019
Messages
37
Thank you to anyone who can help me.

I need to insert 4 blank rows every time there is a value change in column B.
AND, if you're feeling happy, I'd actually like to insert 5 rows...4 blank ones and the 5th being a copy of the header row.
The copy of the header row needs to be exact..same font, same shading, same everything.

I copied this from a different thread but this inserts one blank row. I need 4 blank rows plus a copy of the header row.

Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 3 Step -1
If Range("B" & i).Value <> Range("B" & i - 1).Value Then Rows(i).Insert
Next i
End Sub

This is what I'd end with:

NameStart TimeEnd TimeLocationArea
James
08000830ac
Margaret08000815ac
NameStart TimeEnd TimeLocationArea
Francis09000930ad
Herbert09000930ac
NameStart TimeEnd TimeLocationArea
Willie10001030ac
Ann10001015ac
Annie10001045ad
NameStart TimeEnd TimeLocationArea
Kathy13001330ad
Cathy13001315ad
NameStart TimeEnd TimeLocationArea
Peggy13151330ac

<tbody>
</tbody>

 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try
Code:
Sub Insert_Rows()
  Dim LR As Long, i As Long
  
  Application.ScreenUpdating = False
  LR = Range("A" & Rows.Count).End(xlUp).Row
  For i = LR To 3 Step -1
    If Range("B" & i).Value <> Range("B" & i - 1).Value Then
      Rows(i).Resize(5).Insert
      Rows(i + 4).Resize(, 4).Value = Range("A1:E1").Value
    End If
  Next i
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you so much, Peter.
I KNOW that had probably already been asked, but I couldn't find the thread anywhere.

I appreciate the time you take to stop in here and help us. :)
-Christine
 
Upvote 0
You are very welcome. Glad it worked for you. Thanks for letting us know. :)
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,652
Members
448,975
Latest member
sweeberry

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