AutoFilter Multiple Criteria

Takes2ToTango

Board Regular
Joined
May 23, 2023
Messages
55
Office Version
  1. 365
Platform
  1. Windows
I am trying to auto filter two criteria in the same column so they can both appear. However, when I type the code in and run it, nothing appears
VBA Code:
If ActiveSheet.AutoFilterMode = True Then
Range("C6").AutoFilter field:=2, Criteria1:=Range("D3"), operator:=xlAnd, criteria2:= Range("D3") & "Total"
I am trying to get it so that the range D3 as standard is filtered and the value of D3 plus Total on the end is filtered also.

Is there a way to wildcard a range to say if it includes D3?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I am trying to auto filter two criteria in the same column so they can both appear. However, when I type the code in and run it, nothing appears
VBA Code:
If ActiveSheet.AutoFilterMode = True Then
Range("C6").AutoFilter field:=2, Criteria1:=Range("D3"), operator:=xlAnd, criteria2:= Range("D3") & "Total"
I am trying to get it so that the range D3 as standard is filtered and the value of D3 plus Total on the end is filtered also.

Is there a way to wildcard a range to say if it includes D3?


Please Share a picture of your sample data for more clarity. Thanks
 
Upvote 0
Bit of a guess without seeing some sample data or the entire code, but what happens if you change the operator from xlAnd to xlOr?
 
Upvote 0
Solution
Bit of a guess without seeing some sample data or the entire code, but what happens if you change the operator from xlAnd to xlOr?
Using xlOR did the trick. How come this one worked however but xlAND didn't?
 
Upvote 0
Using xlOR did the trick. How come this one worked however but xlAND didn't?
Because with And you are asking for rows where the value is the range D3 value and the value is the range D3 value & "Total". So if D3 was, say, "a" then you were trying to filter for rows that were "a" and were "aTotal". That is impossible as a row cannot be both those things.

Instead, what it seems you want are rows that are "a" or are "aTotal"
 
Upvote 0
Because with And you are asking for rows where the value is the range D3 value and the value is the range D3 value & "Total". So if D3 was, say, "a" then you were trying to filter for rows that were "a" and were "aTotal". That is impossible as a row cannot be both those things.

Instead, what it seems you want are rows that are "a" or are "aTotal"
I understand! Thank you! That makes more sense to me now
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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