insert rows after change in range of numbers

jelly77

New Member
Joined
Aug 3, 2017
Messages
8
hi,
i have a spreadsheet that contains lots of data and i need to add rows at various points based on cell value in column t, the problem i have is that the column contains continuous data such as below but a lot more
161000
161001
161009
170000
171253
183653
250000
260125
262545
the ranges are the first 2 digits ie. 16, 17, 18, 25 & 26. what i require is for a row to be added after each range. is this possible and if so how would i go about it

many thanks
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try this VBA code:
Code:
Sub MyInsertRows()

    Dim lRow As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Find last row with data in column T
    lRow = Cells(Rows.Count, "T").End(xlUp).Row
    
'   Loop through all last row to top
    For r = lRow To 2 Step -1
'       Check to see if prefix matches row above it
        If Left(Cells(r, "T"), 2) <> Left(Cells(r - 1, "T"), 2) Then
            Rows(r).Insert
        End If
    Next r
    
    Application.ScreenUpdating = True
        
End Sub
 
Upvote 0
You are welcome. Glad I could help.
 
Upvote 0

Forum statistics

Threads
1,224,942
Messages
6,181,902
Members
453,069
Latest member
sivasj

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