Excel VBA Filter More Than 2 Criteria

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
814
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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,400
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
16,524
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
814
Office Version
  1. 2010
Platform
  1. Windows
Thankyou everyone for all your help. Very much appreciated. Works great.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,800
Messages
5,638,430
Members
417,025
Latest member
MusterDuster

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