Forum

Macro to search and...
 
Notifications
Clear all

Macro to search and delete

2 Posts
2 Users
0 Reactions
70 Views
(@kcannon)
Posts: 1
New Member
Topic starter
 

Need a macro that will select the value in A1 on one page and search column A on another page.  If it finds a match, delete that row!

First page will have about 30 values to look up.  Page two could have 20 to 200 values to search through and the row is six columns wide.

 
Posted : 02/03/2019 9:51 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Kavin, welcome to the forum.

Give this a try.

Sub DelRows()
Dim LastRow As Long
Dim i As Long
Dim ValToCompare

'Value to compare
ValToCompare = Sheets("Sheet1").Range("A1").Value

LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
For i = LastRow To 1 Step -1
If Cells(i, 1) = ValToCompare Then
'Delete entire row if cell is equal to ValToCompare
Rows(i).Delete Shift:=xlUp
End If
Next
Application.ScreenUpdating = True
End Sub

Good luck

Sunny

 
Posted : 02/03/2019 8:21 pm
Share: