Excel VBA Filter More Than 2 Criteria

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
961
Office Version
  1. 365
  2. 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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
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]
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
Thankyou everyone for all your help. Very much appreciated. Works great.
 
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

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