Advanced Filter using multiple values in the same criteria

johnnytominaga

New Member
Joined
Apr 27, 2018
Messages
19
Hey guys!

Is it possible to run an Advanced Filter that accounts for multiple values under the same criteria?

Here's what I'd like to achieve:

BEFORE:

IDNamePhone
1John99999999
2Paul22222222
3Sara99999999
4Vanessa11111111
5Andrew99999999

<tbody>
</tbody>

ADVANCED FILTER CRITERIA:
ID<>1
ID<>3
ID<>4
Phone = 99999999

RESULT:

5Andrew99999999

<tbody>
</tbody>

My actual dataset has over 7000 rows and over 30 columns. I'm trying to edit the following code (and multiple formats to add data to Cell B6), but haven't had any success:

Sheet1.Range("$A$1:$C$5").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range('Worksheet'!$A$6:$B$7"), CopyToRange:=Range( _
"'Worksheet'!$A$9:$A$13"), Unique:=False


I'm using Excel 2016 on Windows 10.

Thanks for your help as always,


Johnny
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi Johnny,

First I should apologize and say that there is some logical mishaps here, as far as I can paint the picture you are trying to convey.

Is ID unique or not?

If ID is unique then you do not need to use it. This will leave phone number.

Then you have to decide why you want Andrew, but not John or Sara. What makes the Andrew record different from John and Sara?

So, sorry I do not understand what you are trying to do without knowing how you pick the record you want to get.
 
Upvote 0
Hey Phil!

No need for apologies. Thanks for responding :)

Both IDs and phone numbers repeated throughout the source range. I want to basically filter them out.

If it’s not possible to do it via advanced filter, I guess I can loop through the IDs columns, compare them, remove repeated items’ ranges and sort the results list again, right?

I was wondering if there’s a more simple solution though.

Let me know your thoughts.

Thanks again.
 
Upvote 0
Here is one way using Advanced filter. I have assumed that the original data is on a sheet called 'Data'. Edit the code to match your sheet name.
On either sheet (I've used 'Worksheet') choose anywhere there are 2 vertical vacant cells (I've used F1:F2) and enter a formula as shown below that reflects the conditions you want to meet into the bottom of those 2 cells.


Book1
F
1
2FALSE
Worksheet
Cell Formulas
RangeFormula
F2=AND(Data!A2<>1,Data!A2<>3,Data!A2<>4,Data!C2=99999999)


Then use advanced filter code like this
Code:
Sheets("Data").Range("A$1").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Sheets("Worksheet").Range("F1:F2"), _
    CopyToRange:=Sheets("Worksheet").Range("A9")
 
Upvote 0
Thanks a lot for your response Peter.
That's exactly what I was looking for. I'd never thought of having a blank header and then just filtering the conditions. Brilliant!

Thanks again and have a great day! :)


Here is one way using Advanced filter. I have assumed that the original data is on a sheet called 'Data'. Edit the code to match your sheet name.
On either sheet (I've used 'Worksheet') choose anywhere there are 2 vertical vacant cells (I've used F1:F2) and enter a formula as shown below that reflects the conditions you want to meet into the bottom of those 2 cells.

F
1
2FALSE

<colgroup><col style="width: 25pxpx"><col></colgroup><thead>
</thead><tbody>
</tbody>
Worksheet

Worksheet Formulas
CellFormula
F2=AND(Data!A2<>1,Data!A2<>3,Data!A2<>4,Data!C2=99999999)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>



Then use advanced filter code like this
Code:
Sheets("Data").Range("A$1").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Sheets("Worksheet").Range("F1:F2"), _
    CopyToRange:=Sheets("Worksheet").Range("A9")
 
Upvote 0
Thanks a lot for your response Peter.
That's exactly what I was looking for. I'd never thought of having a blank header and then just filtering the conditions. Brilliant!

Thanks again and have a great day! :)
You are very welcome. Glad it suited your requirement. :)
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

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