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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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