Filter out multiple criteria

kamalm

New Member
Joined
Jul 30, 2018
Messages
33
Hi
I used these codes to filter out two values. How do I write code to filter out more than two values ?

Code:
Range("$A$1:$Z$100000").AutoFilter Field:=3, Criteria1:="<>Ciclo", Criteria2:="<>FROM", Operator:=xlAnd
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
How do I write code to filter out more than two values ?
Use Advanced Filter instead of AutoFilter. Here is an example adding 2 more excluded values.

Code:
Sub AdvFltr()
  Dim rCrit As Range
  
  Set rCrit = Range("AA1:AA2")
  rCrit.Cells(2).Formula = "=AND(C2<>{""Ciclo"",""FROM"",""TO"", ""abc""})"
  Range("$A$1:$Z$100000").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=rCrit, Unique:=False
End Sub
 
Last edited:
Upvote 0
Thanks Peter. But I'm a bit confused with the code. Where is the part that we set which column we want to use the Advanced Filter ?
 
Upvote 0
Thanks Peter. But I'm a bit confused with the code. Where is the part that we set which column we want to use the Advanced Filter ?
It is in the formula in rCrit. In your first post you had a range starting in column A and were filtering on Field:=3 which would be column C. So in my formula ..

Rich (BB code):
Sub AdvFltr()
  Dim rCrit As Range
  
  Set rCrit = Range("AA1:AA2")
  rCrit.Cells(2).Formula = "=AND(C2<>{""Ciclo"",""FROM"",""TO"", ""abc""})"
  Range("$A$1:$Z$100000").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=rCrit, Unique:=False
End Sub
 
Upvote 0
Now I get it and your code is work very well :) One last thing for this topic peter, what should I write if I want to filter out the blank cells ?

And, the code you gave me just now for one column. How the code looks like if I want to have multiple column with multiple values ?
 
Upvote 0
One last thing for this topic peter, what should I write if I want to filter out the blank cells ?
Just add 'blank' as one of the values to exclude like the others
Rich (BB code):
rCrit.Cells(2).Formula = "=AND(C2<>{""Ciclo"",""FROM"",""TO"", ""abc"",""""})"


And, the code you gave me just now for one column. How the code looks like if I want to have multiple column with multiple values ?
That is way too vague a description. Could you give a small set of sample dummy data, expected results and explanation in relation to that sample data? My signature block below has help, if needed, with how to show sample data that we can copy and test with.
 
Last edited:
Upvote 0
When you say:
I used these codes to filter out two values

Can we just delete the rows that meet your criteria.
Filter out like your using does not delete the rows
 
Upvote 0
Just add 'blank' as one of the values to exclude like the others
Rich (BB code):
rCrit.Cells(2).Formula = "=AND(C2<>{""Ciclo"",""FROM"",""TO"", ""abc"",""""})"


That is way too vague a description. Could you give a small set of sample dummy data, expected results and explanation in relation to that sample data? My signature block below has help, if needed, with how to show sample data that we can copy and test with.

ABCDEFGHI
1181424/05/201812:52:15
21815*****
3181624/05/201812:52
41817A-07:STZ1(ALARMBEGIN)
51818*****DBG00
61819---------------
7182024/05/201812:54:10
81821*****STZ0
9182224/05/201812:53
101823RICHIESTASTARTDOSATORE
111824*****DBG00
121825---------------
13182624/05/201812:54:36[N][N]STZ11*Set18520,00
141827---------------
15182824/05/201812:54:41[N][N]STZ11*Set18520,00
161829---------------
17183024/05/201812:54:45[N][N]STZ11*Set18520,00
181831---------------
19183224/05/201812:54:51[N][N]STZ11*Set18520,00
201833---------------
21183424/05/201812:54:59[N][N]STZ13*CD_U340,4
221835---------------
23183624/05/201812:55:03[N][N]STZ31*Set1480,00
241837---------------
25183824/05/201812:55:07[N][N]STZ31*Set1480,00
261839---------------
27184024/05/201812:55:13[N][N]STZ33*CD_U1150,6
281841--------Ciclo0terminato
291842---------------
30184324/05/201812:55:46[N][N]STZ1NORMPS-33,63
311844---------------
32184524/05/201812:55:52[N][N]STZ3NORMPS18997,31
331846--------Ciclo1terminato
341847---------------
35184824/05/201812:56:25[N][N]STZ1NORMPS-28,10
361849---------------
37185024/05/201812:56:31[N][N]STZ3NORMPS19017,79
381851--------Ciclo2terminato
391852---------------STZ2
40185324/05/201812:57:04[N][N]STZ1NORMPS-26,49
411854---------------
42185524/05/201812:57:10[N][N]STZ3NORMPS18680,38
431856--------Ciclo3terminato
441857---------------FROM
45185824/05/201812:57:42[N][N]STZ1NORMPS-28,23

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




Above is the sample data. I want o filter out:
Column C = Ciclo, DBG00, FROM, 'blank'
Column D = STZ0, STZ1, STZ2, DOSATORE, 'blank'
Column E = ALARM
Column H = Set
 
Upvote 0
Your original post seemed to indicate you wanted to filter out all values that do not equal:
Ciclo, DBG00, FROM

But it seems to me your last post said filter out.
Values that do equal.

Would you clarify this
 
Upvote 0

Forum statistics

Threads
1,214,598
Messages
6,120,441
Members
448,966
Latest member
DannyC96

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