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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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:

[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][td="bgcolor:#C0C0C0"]
C​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td][/td][td]sheep[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td][/td][td]dog[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td][/td][td]cat[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td="bgcolor:#F3F3F3"]
Data
[/td][td="bgcolor:#F3F3F3"]
Check
[/td][td="bgcolor:#F3F3F3"]
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
6​
[/td][td]A wolf in sheep's clothiong[/td][td]
1​
[/td][td]B6: =SUMPRODUCT(COUNTIF(A6, "*" & $B$1:$B$3 & "*"))[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
7​
[/td][td]How now brown cow?[/td][td]
0​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
8​
[/td][td]Who let the dogs out?[/td][td]
1​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
9​
[/td][td]The cow jumped over the moon[/td][td]
0​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
10​
[/td][td]He's a cool cat[/td][td]
1​
[/td][td][/td][/tr]
[/table]
 
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,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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