Hi guys, I found this code in this thread:
https://www.mrexcel.com/forum/excel...elete-rows-if-column-contains-value-list.html
And it works perfectly, but I am not sure how to apply the same code for the entire worksheet vs. just the active sheet? Any help will be super appreciated! Thank you!
Here is the code:
https://www.mrexcel.com/forum/excel...elete-rows-if-column-contains-value-list.html
And it works perfectly, but I am not sure how to apply the same code for the entire worksheet vs. just the active sheet? Any help will be super appreciated! Thank you!
Here is the code:
Code:
Sub Example1()
Dim rngFound As Range, rngToDelete As Range
Dim strFirstAddress As String
Dim varList As Variant
Dim lngCounter As Long
Application.ScreenUpdating = False
varList = Range("Sheet1!A2:A200").Value
For lngCounter = LBound(varList) To UBound(varList)
With ActiveSheet.Range("A:A")
Set rngFound = .Find( _
What:=varList(lngCounter, 1), _
Lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=True _
)
If Not rngFound Is Nothing Then
If rngToDelete Is Nothing Then
Set rngToDelete = rngFound
Else
Set rngToDelete = Application.Union(rngToDelete, rngFound)
End If
strFirstAddress = rngFound.Address
Set rngFound = .FindNext(After:=rngFound)
Do Until rngFound.Address = strFirstAddress
Set rngToDelete = Application.Union(rngToDelete, rngFound)
Set rngFound = .FindNext(After:=rngFound)
Loop
End If
End With
Next lngCounter
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: