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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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