troubleshooting Question

perform a quick delete of rows containing one of several different words

Avatar of Jagwarman
Jagwarman asked on
Microsoft Excel
16 Comments1 Solution246 ViewsLast Modified:
I need to be able to delete rows that 'do not' contain one of 5 different words. The spreadsheet contains several thousand rows so I am looking for a way to delete them quickly. I have this piece of code which deletes quickly but it deletes the rows containing the word, if I could change it to delete anything that is 'not equal' to these words it would be fine. Or a new macro :-)

Dim i As Long
    Application.ScreenUpdating = False
    For i = Cells(Rows.Count, 2).End(xlUp).Row To 1 Step -1
        If InStr(1, Cells(i, 2).Value, "ONE", 1) Or _
        InStr(1, Cells(i, 2).Value, "TWO", 1) Or _
        InStr(1, Cells(i, 2).Value, "THREE", 1) Or _
        InStr(1, Cells(i, 2).Value, "FOUR", 1) Or _
        InStr(1, Cells(i, 2).Value, "FIVE", 1) _
        Then Cells(i, 2).EntireRow.Delete
    Next i

Thanks
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 16 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros