Multiple criteria in autofilter

Tucker92

Board Regular
Joined
Jun 7, 2018
Messages
53
Hi i am trying to get this piece of code to work and i cant figure out why it isnt working. All the variables are assigned and it works if i only use the one criteria. Can anyone help me to get this to work
When i use it it comes back with a 1004 error

Code:
WTL.Range("WTL").AutoFilter Field:=3, Criteria1:="=*" & met & "*", Criteria2:="=*" & metf & "*", Criteria3:="=*" & rsv & "*", VisibleDropDown:=True

I could use it to filter out each one individually but i am trying to cut my code down and thought i would be able to combine these

Thank you in advance for any help
 
Last edited:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Autofilter only has 2 criteria arguments, Criteria1 and Criteria2.

What are you trying to filter for?
 
Upvote 0
Five different criteria but the names change each week so i need to search for it using the portion that doesnt change

Here is my entire code

Code:
Dim ws As WorksheetDim Vac As Worksheet


    Set Vac = Application.Workbooks("Css Plan").Sheets("Vac AC WTL")
    Set WTL = Application.Workbooks("Css Plan").Sheets("WTL")


Dim met As String, metf As String, rsv As String, pl As String, wet As String


    met = "12""MET"
    metf = "14""MET"
    rsv = "RSV"
    pl = "14""PL"
    wet = "12""WET"
    
Dim data_end_row_number As Long
Dim nxt As Long
     
data_end_row_number = WTL.Range("A1").End(xlDown).Row
nxt = Vac.Range("A1").End(xlDown).Row + 1


   WTL.Range("WTL").AutoFilter Field:=3, Criteria1:="=*" & met & "*", Criteria2:="=*" & metf & "*", Criteria3:="=*" & rsv & "*", VisibleDropDown:=True
            
    WTL.Activate
    WTL.Range(("A2"), Cells(data_end_row_number, "D")).SpecialCells(xlCellTypeVisible).Copy
    Vac.Activate
    Range("A2").Select
    ActiveSheet.Paste
    WTL.Activate

Is there any way i can include all 5
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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