'Cycle Multiple strings
I am using this macro which works fine but it's not flexible or as fast it should be. Basically I think it's better to add the BanWords in an array and cycle through them and delete rows.
Sub delete_data(sh As Worksheet, col As String)
Dim a As Variant, aWords As Variant
Dim i As Long, j As Long
Dim BanWords As String
Dim lastrow As Long
Application.StatusBar = "Deleting Data..."
'Exceptions List
BanWords = "2019,2020,2021"
sh.Activate
''Find Last Row
With sh
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
'Reverse Iteration
For i = lastrow To 2 Step -1
If InStr(1, Range(col & i), "2019") <> 0 Then Rows(i).EntireRow.Delete
If InStr(1, Range(col & i), "2020") <> 0 Then Rows(i).EntireRow.Delete
If InStr(1, Range(col & i), "2021") <> 0 Then Rows(i).EntireRow.Delete
Next i
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
