Insert rows if...

mikebecker

Board Regular
Joined
Mar 28, 2004
Messages
227
I have Col A:B that is a master list. I have Col C:D that is a partial list of Col A:B with data in cols E:O.

I want to insert empty cells in C:O if C:D<>A:B.

Ideas?

Mike
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Like this?:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    
    If Cells(Target.Row, 1) = "" Or Cells(Target.Row, 2) = "" Or Cells(Target.Row, 3) = "" Or Cells(Target.Row, 4) = "" Then GoTo exitMe
    If Cells(Target.Row, 1) <> Cells(Target.Row, 3) And Cells(Target.Row, 2) <> Cells(Target.Row, 4) Then
        Range("C" & Target.Row & ":O" & Target.Row).Insert (-4121)
    End If

exitMe:
    Application.EnableEvents = True

End Sub

Press Alt-F11 to open the VBE.
Press Control-R to open the Project Explorer.
Click "Microsoft Excel Objects" for the file you're working on.
Double-click the sheet where you need this to work.
Open the Code pane with F7.
Paste the above code in.
Press Alt-Q to close the VBE and return to Excel.

Hope that helps!
 
Upvote 0

Forum statistics

Threads
1,203,067
Messages
6,053,333
Members
444,654
Latest member
Rich Cohen

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