Search for Multiple Strings in Column and Delete Row if none found

Emoncada

Active Member
Joined
Mar 23, 2005
Messages
409
I have Multiple Sentences in Column A. I have 3 different Criteria's I need to locate in that column.
So example search for " *Alert Red* ", Or " *Successful Job* ", Or " *Failed with Error* "

Any of those phrases in the sentences in Column A i want to keep and delete the rest of the rows.

Any help would be appreciated.

Thanks,
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Assumes your sentences start in cell A1 - change to suit. Note this is case sensitive to the search strings.
Rich (BB code):
Sub Emoncada()
Dim Phrases As Variant, V As Variant, i As Long, j As Long, Ct As Long
Phrases = Array("*Alert Red*", "*Successful Job*", "*Failed with Error*")
With Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
    V = .Value
    For i = 1 To UBound(V, 1)
        Ct = 0
        For j = LBound(Phrases) To UBound(Phrases)
            If V(i, 1) Like Phrases(j) Then Exit For
            Ct = Ct + 1
            If Ct = UBound(Phrases) + 1 Then V(i, 1) = "#N/A"
        Next j
    Next i
    Application.ScreenUpdating = False
    .Value = V
    On Error Resume Next
    .SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
End With
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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