Inserting Rows into sets of Sequential data

wills3rd

New Member
Joined
Sep 14, 2005
Messages
4
I have a large list of data that appears in sequential blocks - mostly pairs and triplicates. I need to create a macro that inserts a blank line between each sequantial set. For example: if the list were 1,2,5,6,7,9,10,12 I would need to insert lines between 2 and 5, 7 and 9 and 10 and 12.

Could you please help me to do this? Thank you.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
HI wills3rd
Welcomr to the board

Assuming the data in Sheet2 in column A starting in A1:

Code:
Sub InsertBlanks()
Dim lRow As Long, lLastRow As Long

With Worksheets("Sheet2")
    lLastRow = .Range("A" & .Rows.Count).End(xlUp).Row

    For lRow = lLastRow To 2 Step -1
        If .Range("A" & lRow).Value <> .Range("A" & lRow - 1).Value + 1 Then
            .Rows(lRow).Insert
            lRow = lRow - 1
        End If
    Next
End With
End Sub


Hope this helps
PGC
 

Forum statistics

Threads
1,141,678
Messages
5,707,782
Members
421,527
Latest member
Tamiwsw

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