Insert 3 blank rows when value changes

NiklasNordkvist

New Member
Joined
Jan 5, 2023
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have sheet with huge amount of data and need to insert 3 blank rows when value in column 'C' changes starting from row 5.
Is that possible with VBA and does someone know a "simple" code for that?

Picture below shows how I would like the result to be:

1713273821011.png
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try:
VBA Code:
Sub InsertRows()
    Application.ScreenUpdating = False
    Dim x As Long, lRow As Long
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For x = lRow To 6 Step -1
        Range("A" & x).Resize(3).EntireRow.Insert
    Next x
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try:
VBA Code:
Sub InsertRows()
    Application.ScreenUpdating = False
    Dim x As Long, lRow As Long
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For x = lRow To 6 Step -1
        Range("A" & x).Resize(3).EntireRow.Insert
    Next x
    Application.ScreenUpdating = True
End Sub
Hi, thank you for taking your time!

It worked fine in the exampel sheet that I posted a picture of.
But in the actual sheet I get this:
1713284025137.png
 
Upvote 0
A macro that works on sample data very often won't work with actual data. Also, it is hard to work with a picture. It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0

Forum statistics

Threads
1,215,206
Messages
6,123,636
Members
449,109
Latest member
Sebas8956

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