Filtering all data by one column that CONTAINS a defined set of words

Dougmeister

New Member
Joined
Sep 23, 2010
Messages
42
I have a list of eleven (11) terms by which that I need to filter the data in column "C". If any row contains any of these terms, I want to show only those rows.

I can keep it on the same tab.

I need to repeat this every month with new data.

What is the easiest way to do this?
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Maybe using Advanced Filter but we need more information to help.
Try to show us a small data sample, including the list of terms, along with expected results.

M.
 
Upvote 0
I'd add a column with a formula and filter on that:

A​
B​
C​
1​
sheep
2​
dog
3​
cat
4​
5​
Data
Check
6​
A wolf in sheep's clothiong
1​
B6: =SUMPRODUCT(COUNTIF(A6, "*" & $B$1:$B$3 & "*"))
7​
How now brown cow?
0​
8​
Who let the dogs out?
1​
9​
The cow jumped over the moon
0​
10​
He's a cool cat
1​
 
Upvote 0
How is this? Filter Screenshot #1 ("Books") byScreenshot #2 ("Abbreviations") to show only the books inScreenshot #3 ("Books (filtered)").

(I didn't know how to create a table like shg did, so here are screenshots...)

Screenshot #1

37568422046_afa39eafdb_m.jpg


Screenshot #2
37568422056_2747c8a19d_m.jpg



Screenshot #3

37568421996_d0af5f3c89_m.jpg


This is greatly simplified. The actual data to use as the filter will contain at least 100 phrases/abbreviations. As the list will change occasionally, I think that performing this filtering via VBA would be best.
 
Last edited:
Upvote 0
Maybe something like this

1. First of all:
Change the value of A5 in sheet Abbreviations from JS to (JS)

2. Go to Sheet Books
put in C1
Check

Formula in C2
=--(SUMPRODUCT(--ISNUMBER(FIND(" "&Abbreviations!$A$2:$A$7&" "," "&B2&" ")))>0)

3. Go to sheet Books (Filtered) and follow these steps

Data > Advanced Filter and set the parameters as
List Range:Books!$A$1:$B$11
Criteria Range: Books!$C$1:$C$2
pick Copy to another location and
Copy to: 'Books (Filtered)'!$A$1
Ok

(you can select the proper ranges to set the parameters)

Hope this helps

M.
 
Upvote 0
Thanks!

Is there a way to recalculate the output without going into the Excel menu options ("Data > Advanced Filter", etc.)? By putting some code in a VBA module? Keyboard shortcut to recalculate, etc.?
 
Upvote 0
Turn-on the macro recorder;
Do all the process manually (insert header in C1, formula in C2. etc etc);
Turn-off the macro recorder
You've gotten the code!

M.
 
Upvote 0
With some adjustments in the recorded code, i've gotten this code. It worked for me.

Code:
Sub AdvFilter()
    Dim lastRow As Long
    
    With Sheets("Books")
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        .Range("C1") = "Check"
        .Range("C2").Formula = _
        "=--(SUMPRODUCT(--ISNUMBER(FIND("" ""&Abbreviations!A$2:A$7&"" "","" ""&B2&"" "")))>0)"
    End With
    
    Sheets("Books (Filtered)").Select
    Sheets("Books").Range("A1:B" & lastRow).AdvancedFilter _
        Action:=xlFilterCopy, CriteriaRange:=Sheets("Books").Range("C1:C2"), _
        CopyToRange:=Range("A1"), Unique:=False
End Sub

M.
 
Upvote 0
Is there a limit to the number of rows this method can handle? It works fine for my sample, but when I use my actual data, there are over 8,000 rows and it ends up returning rows that do not match the search terms on the "Abbreviations" tab.

I neglected to mention (and I apologize) that some of the "abbreviations" have spaces in the middle (i.e., can be multiple "words"). Does that change anything?

To get more results, I also had to change this line:

Code:
=--(SUMPRODUCT(--ISNUMBER(FIND(" "&Abbreviations!$A$2:$A$31&" "," "&B2&" ")))>0)

to:

Code:
=--(SUMPRODUCT(--ISNUMBER(FIND(Abbreviations!$A$2:$A$31,B2)))>0)
 
Last edited:
Upvote 0
The macro was created considering the sample data you showed us. If your actual case is different, it will not work. But I think you may have understood the logic and that you can adapt it.
Always try to show a sample that really matches your data.

M.
 
Upvote 0

Forum statistics

Threads
1,216,109
Messages
6,128,880
Members
449,477
Latest member
panjongshing

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