I have a spreadsheet and I need to delete all rows that do NOT have specified values in a column. Essentially I would like to delete all rows that do not contain specific words from a preserve list. The cells in the column will have full sentences in them so I want it to just isolate if the specified word exists anywhere in the cell and NOT delete that row.
I have two working ways to do something similar to this:
Method 1:
Method 1 works by making an array of the values I want to preserve, but it does not seem to be able (or I can't figure out how) to make it wildcard based so that the value can exist anywhere in the cell.
Method 2:
Method 2 works with the wildcard "*" but I can't figure out how to add additional values to not be deleted.
I have two working ways to do something similar to this:
Method 1:
VBA Code:
Sub deletexptlst()
Dim List As Variant
Dim LR As Long
Dim r As Long
List = Array("Value 1", "Value 2", "Value 3", "Value 4")
LR = Range("E" & Rows.Count).End(xlUp).Row
For r = LR To 2 Step -1
If IsError(Application.Match(Range("E" & r).Value, List, False)) Then
Rows(r).Delete
End If
Next r
End Sub
Method 1 works by making an array of the values I want to preserve, but it does not seem to be able (or I can't figure out how) to make it wildcard based so that the value can exist anywhere in the cell.
Method 2:
VBA Code:
Sub delallexcept()
Dim LR As Long, i As Long
LR = Range("E" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
If Not Range("E" & i).Value Like "*Value*" Then Rows(i).Delete
Next i
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
Method 2 works with the wildcard "*" but I can't figure out how to add additional values to not be deleted.