VBA to insert rows

zombiemaster

Board Regular
Joined
Oct 27, 2009
Messages
241
I'm working with Excel 2003.

I need to insert 2 blank rows within a spreadsheet above certain other rows that contains data that starts with a particular text string.

Details:
Column A has office codes in the form of "0301A", "0301B", etc.
Column F will have billing codes that could start with either "L" or "ND" or "NF".

Problem:
I want to separate the L's from the ND's and also the NF's in column F based on which office they are billed to.

End result:
What I want to end up with are two blank rows in between each office code in column A, then another two blank rows between the L's, ND's and NF's.

I'm studying VBA for Excel now but haven't gotten very far yet...I can record macros with the macro recorder and tweak them a little with VBA but I'm not to this level yet. Can anybody give me a hand with this?

Thanks...

-=ZM=-
 
oops again. didn't test it.

Rich (BB code):
Sub InsRows()
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = LR To 9 Step -1 'stop at row 9 itself (2nd row with values)
    With Range("F" & i)
        If .Offset(, -4).Value <> .Offset(-1, -4).Value Then 'non matching B rows
            .Resize(2).EntireRow.Insert
        ElseIf Left(.Value, 1) <> Left(.Offset(-1).Value, 1) Then  'non matching first letter in F
            .Resize(2).EntireRow.Insert
        ElseIf Mid(.Value, 1, 1) = "N" And Mid(.Value, 2, 1) <> Mid(.Offset(-1).Value, 2, 1) Then
            .Resize(2).EntireRow.Insert
        End If
    End With
Next i
End Sub
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,215,942
Messages
6,127,807
Members
449,408
Latest member
Bharathi V

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