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:
I'm sorry if I have made you confused. I actually want to filter out those values that I mentioned above.
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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
So, if we did all that with that sample data, am I right in thinking that the only remaining visible rows would be the ones shown green below? I have marked all the cells that meet any of your conditions with yellow so those rows would be filtered out as I understand it.


Book1
ABCDEFGHI
1ABCDEFGHI
2181424/05/201812:52:15
31815*****
4181624/05/201812:52
51817A-07:STZ1(ALARMBEGIN)
61818*****DBG00
71819---------------
8182024/05/201812:54:10
91821*****STZ0
10182224/05/201812:53
111823RICHIESTASTARTDOSATORE
121824*****DBG00
131825---------------
14182624/05/201812:54:36[N][N]STZ11*Set18520,00
151827---------------
16182824/05/201812:54:41[N][N]STZ11*Set18520,00
171829---------------
18183024/05/201812:54:45[N][N]STZ11*Set18520,00
191831---------------
20183224/05/201812:54:51[N][N]STZ11*Set18520,00
211833---------------
22183424/05/201812:54:59[N][N]STZ13*CD_U340,4
231835---------------
24183624/05/201812:55:03[N][N]STZ31*Set1480,00
251837---------------
26183824/05/201812:55:07[N][N]STZ31*Set1480,00
271839---------------
28184024/05/201812:55:13[N][N]STZ33*CD_U1150,6
291841--------Ciclo0terminato
301842---------------
31184324/05/201812:55:46[N][N]STZ1NORMPS-33,63
321844---------------
33184524/05/201812:55:52[N][N]STZ3NORMPS18997,31
341846--------Ciclo1terminato
351847---------------
36184824/05/201812:56:25[N][N]STZ1NORMPS-28,10
371849---------------
38185024/05/201812:56:31[N][N]STZ3NORMPS19017,79
391851--------Ciclo2terminato
401852---------------STZ2
41185324/05/201812:57:04[N][N]STZ1NORMPS-26,49
421854---------------
43185524/05/201812:57:10[N][N]STZ3NORMPS18680,38
441856--------Ciclo3terminato
451857---------------FROM
46185824/05/201812:57:42[N][N]STZ1NORMPS-28,23
Sheet1



If I happen to be right about the remaining rows, then for this sample data the same result could be achieved with AutoFilter by filtering column D to only show [N][N] and column H to not show Set
Would that be true for any of your data?
 
Last edited:
Upvote 0
If I happen to be right about the remaining rows, then for this sample data the same result could be achieved with AutoFilter by filtering column D to only show [N][N] and column H to not show Set
Would that be true for any of your data?

omg you're so genius Peter. This way more simple and easy. Never realized that I actually want the rows that have [N][N] only. God bless you, thank you!
 
Last edited by a moderator:
Upvote 0
omg you're so genius Peter. This way more simple and easy. Never realized that I actually want the rows that have [N][N] only. God bless you, thank you!
Best not to fully quote long posts as it makes the thread harder to read/navigate. If you want to quote, quote small, relevant parts only. I've edited your post to do that. :)

Just to confirm, you need to AutoFilter two columns as there are some [N][N] rows that you apparently don't want. Is that what you are doing?
 
Upvote 0
Just to confirm, you need to AutoFilter two columns as there are some [N][N] rows that you apparently don't want. Is that what you are doing?

Yup. This is my code I did just now and it works.
Code:
Cells.Select
    Selection.AutoFilter
    ActiveSheet.Range("A1:A" & Range("B" & Rows.Count).End(xlUp).Row).AutoFilter Field:=4, Criteria1:="[N][N]"
    ActiveSheet.Range("A1:A" & Range("B" & Rows.Count).End(xlUp).Row).AutoFilter Field:=8, Criteria1:="<>Set"

Perhaps you have better or shorter one.
 
Upvote 0
Perhaps you have better or shorter one.
I would definitely not 'Select' anything. Selecting is rarely needed and tends to slow your code and can make any screen flickering worse.
You also only need to calculate the range once.
This is how I would write it. (I've assumed the sheet's used range)
Code:
With ActiveSheet.UsedRange
  .AutoFilter Field:=4, Criteria1:="[N][N]"
  .AutoFilter Field:=8, Criteria1:="<>Set"
End With
 
Upvote 0
What is actually UsedRange ? Does it mean select all cells contain values ?
It can mean that but it can also get a bit tricky depending on what has been going on in your worksheet. You might have to do some research about that. Here's one place to start.
 
Upvote 0
It can mean that but it can also get a bit tricky depending on what has been going on in your worksheet. You might have to do some research about that. Here's one place to start.

Oh I see. Will go through it later. Thank you so much Peter. learnt a lot from you:)
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
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