troubleshooting Question

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

Avatar of Jagwarman
Jagwarman asked on
Microsoft Excel
16 Comments2 Solutions246 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
ASKER CERTIFIED SOLUTION
Steve
Cost Accountant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2012

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 2 Answers and 16 Comments.
Start Free Trial
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 2 Answers 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