Filter Out Cells That Contain Certain Words

synystyr1

New Member
Joined
Nov 21, 2012
Messages
1
I have searched the forum for a couple of days and have not quite found an answer to this question or maybe I did and didn't understand it (I am a ultra noob), but I am looking to write code to filter out rows that contain certain words in them. The code I am using is

ActiveSheet.Range("$A$1", "$Q" & CLastRow).CurrentRegion.AutoFilter Field:=11, Criteria1:=Array("<>*Crew Rest*", "<>*Leather*", "<>*Curtain*", "<>*Pocket*"), Operator:=xlAnd

Using this, it only filters out the last criteria value. What am I doing wrong or is there another way to do it? XL2007
 
Maybe using Advanced filter

Something like this
Assumes
Data in Sheet1
headers in A1:Q1
field to be filtered in column K

Code:
Sub aTest()
    Dim lastRow As Long
    
    With Sheets("Sheet1") '<--Adjust to suit
        .AutoFilterMode = False
        
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        
        .Range("Z2").Formula = _
            "=SUM(INDEX(--ISNUMBER(SEARCH({""Crew Rest"";""Leather"";""Curtain"";""Pocket""},K2)),0))=0"
        
        .Range("A1:Q" & lastRow).AdvancedFilter Action:=xlFilterInPlace, _
            CriteriaRange:=.Range("Z1:Z2"), Unique:=False
    End With
End Sub

M.
 
Upvote 0

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