macro - find two items, insert row

psrs0810

Well-known Member
Joined
Apr 14, 2009
Messages
1,109
Is there a way to find two items in different columns, select that row and insert.

So in column B I am looking for "A Total". In column D I am looking for "M". where those two are on the same row to insert a row.

How can this be achieved without out concatenating the information?

Thank you
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
This should do the trick.

Sub InsertRow()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual 'pre XL97 xlManual

'Loop backwards through the rows in the range that you want to evaluate.

Set ws = ActiveSheet
For i = 1 To Cells.SpecialCells(xlLastCell).Row
If ws.Cells(i, 2).Value = "A Total" And _
ws.Cells(i, 4).Value = "M" Then
ws.Cells(i, 1).EntireRow.Insert
i = i + 1
End If
Next
done:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
 
Upvote 0
My initial code did not account for the additional rows added.

This should work better and insert two rows as it starts at the bottom of the existing data.

Sub InsertRow()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual 'pre XL97 xlManual

'Loop backwards through the rows in the range that you want to evaluate.

Set ws = ActiveSheet
For i = Cells.SpecialCells(xlLastCell).Row To 1 Step -1
If ws.Cells(i, 2).Value = "A Total" And _
ws.Cells(i, 4).Value = "M" Then
ws.Cells(i, 1).EntireRow.Insert
ws.Cells(i, 1).EntireRow.Insert
End If
Next
done:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,136
Members
452,890
Latest member
Nikhil Ramesh

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