VBA: Autofilter xlOr Operator >than 2 Criteria

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
210
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I have this VBA code that works for two criteria, but not three.
  1. How do I get it to auto-filter for three or more filters?
  2. How do I change the range to last row, instead of adding the I8000? I tried to change to"$A$4:$I & lastRow" but didn't work for me.
Rich (BB code):
.Range("$A$4:$I$8000").AutoFilter Field:=3, Criteria1:="=apples", Operator:=xlOr, Criteria2:="=oranges", Operator:=xlOr, Criteria3:="=kiwi"
 
Last edited by a moderator:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
How about
VBA Code:
.Range("$A$4:$I$8000").AutoFilter 3, Array("apples", "oranges", "kiwi"), xlFilterValues
 
Upvote 1
Solution
How about
VBA Code:
.Range("$A$4:$I$8000").AutoFilter 3, Array("apples", "oranges", "kiwi"), xlFilterValues

Fluff That worked! Thank you! Now only if I can get the &lastrow to work then my day is done.​

 
Upvote 0
Please do not post everything in big bold text, just use the normal font.

Can you post the code that is setting the lastrow.
 
Upvote 0
Sorry Fluff. No idea how it all came out bolded. I didn't mean to have it bolded.
Below is the first part that I was trying to change to last row. but it won't work for me.

VBA Code:
.Range("$A$4:$I & lastRow")
 
Upvote 0
It should be like
VBA Code:
.Range("$A$4:$I" & lastRow)
 
Upvote 0
It should be like
VBA Code:
.Range("$A$4:$I" & lastRow)
I tried that and it threw me an error code - Compile error: Argument not optional.
I don't know what that means.
VBA Code:
.Range("$A$4:$I & lastRow").AutoFilter 3, Array("apples", "oranges", "kiwi"), xlFilterValues
 
Upvote 0
You still have the quotes in the wrong place for the range.
 
Upvote 0
Fluff, thank you so much for all your help. I'm all good now.
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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