VBA AutoFilter for Multiple Criteria

chethead

New Member
Joined
Jul 23, 2015
Messages
45
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I don't really understand VBA but try to cobble things together from what I find online. However, I cannot figure this out. I've got 3 items I am looking to filter based on dropdown lists. The headers are Status, Estimator and Manager and the cells that they represent where the dropdown lists exist are F2, G2 and H2. The first VBA I tried works, but only if I have all thee lists populated:

VBA Code:
Sheets("Proposals").Range("A4").AutoFilter Field:=6, Criteria1:=Cells(2, 6).Value
Sheets("Proposals").Range("A4").AutoFilter Field:=7, Criteria1:=Cells(2, 7).Value
Sheets("Proposals").Range("A4").AutoFilter Field:=8, Criteria1:=Cells(2, 8).Value

Very rarely would we have all 3 items selected so I tried something that appears to have wildcards where I don't have to have items selected in all three dropdowns:

VBA Code:
Sub Filter()

    Dim Status As String
    Dim Estimator As String
    Dim Manager As String
    Dim rng As Range
   
Status = Proposals.Range("F2").Value
Estimator = Proposals.Range("G2").Value
Manager = Proposals.Range("H2").Value

  Set rng = Proposals.Range("A4")

  If Status = "" Then Status = "*"
  If Estimator = "" Then Estimator = "*"
  If Manager = "" Then Manager = "*"

        rng.AutoFilter Field:=6, Criteria1:=Status & "*"
        rng.AutoFilter Field:=7, Criteria1:=Estimator & "*"
        rng.AutoFilter Field:=8, Criteria1:=Manager & "*"
   
End Sub

This doesn't seem to work at all. I get a Run-time error '424': Object required.

Any help would be appreciated!

Thank you,

Rob
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
How about
VBA Code:
  If Status = "" Then rng.AutoFilter Field:=6 Else rng.AutoFilter Field:=6, Criteria1:=Status
  If Estimator = "" Then rng.AutoFilter Field:=7 Else rng.AutoFilter Field:=7, Criteria1:=Estimator
  If Manager = "" Then rng.AutoFilter Field:=8 Else rng.AutoFilter Field:=8, Criteria1:=Manager
 
Upvote 0
Thank you Fluff. I copied and pasted your idea into the first VBA code I have listed above but am now receiving the Run-time error '424': Object required on that spreadsheet too
 
Upvote 0
Which line of code gave the error?
 
Upvote 0
Which line of code gave the error?
The first line

Capture.JPG
 
Upvote 0
You need to put that into your code, replacing this
VBA Code:
 If Status = "" Then Status = "*"
  If Estimator = "" Then Estimator = "*"
  If Manager = "" Then Manager = "*"

        rng.AutoFilter Field:=6, Criteria1:=Status & "*"
        rng.AutoFilter Field:=7, Criteria1:=Estimator & "*"
        rng.AutoFilter Field:=8, Criteria1:=Manager & "*"
 
Upvote 0
Oh - I did not understand initially. Still same error though

Capture.JPG


Cell F2 is where I choose between 3 status types, it is a drop down. G2 and H2 are similar, choosing estimator and manager respectively.

Any other thoughts?
 
Upvote 0
Is the the sheet name as seen on the tab, or is the sheet codename as seen in the vb editor project window?
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,736
Members
448,988
Latest member
BB_Unlv

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