Excel VBA Filter More Than 2 Criteria

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
864
Office Version
  1. 2010
Platform
  1. Windows
Hi everyone,

Is there another option to adding a 3rd Criteria:

Sub AutoSortSetsR()

Dim AAMin As Long
Dim AAMax As Long


AAMin = Sheets("Sets").Range("H28").Value
AAMax = Sheets("Sets").Range("J28").Value


Sheets("1000Numbers").Select

Selection.AutoFilter Field:=18, Criteria1:="=" & AAMin, Operator:=xlOr, _
Criteria2:="=" & AAMax


Sheets("Sets").Select
Range("F19").Select


End Sub


Thanks in advance!!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,450
If you have Excel 2007 or later, you can use an Array for the filter criteria.

Code:
Selection.AutoFilter Field:=18, Criteria1:=[B]Array(AAMin, AAMax, AAOther), Operator:=xlFilterValues[/B]
 

RudiS

Active Member
Joined
May 7, 2015
Messages
349
Something like this should work...

Code:
Sub AutoSortSetsR()
Dim AAMin As Long
Dim AAMax As Long
Dim Filter3 As Long


    AAMin = Sheets("Sets").Range("H28").Value
    AAMax = Sheets("Sets").Range("J28").Value
    Filter3 = 100
    
    Sheets("1000Numbers").Select
    Selection.AutoFilter Field:=18, Criteria1:=Array(AAMin, AAMax, Filter3), Operator:=xlFilterValues


    Sheets("Sets").Select
    Range("F19").Select


End Sub
 

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
17,035
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I think is necessary to convert the values to strings, i.e., the criteria-array has to be an array of strings

Something like

Code:
Sheets("1000Numbers").Select
ActiveSheet.Range("A1").AutoFilter Field:=18, _
        Criteria1:=Array(CStr(AAMin), CStr(AAMax), CStr(AAOther)), Operator:=xlFilterValues

M.
 

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
864
Office Version
  1. 2010
Platform
  1. Windows
Thankyou everyone for all your help. Very much appreciated. Works great.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,525
Messages
5,837,867
Members
430,519
Latest member
abtg1

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
Top