VBA Autofilter using two filters

Double99

New Member
Joined
Jul 11, 2011
Messages
29
Hi,

I have wrote the following VBA Code which performs two filters in a spreadsheet.

Sheets("AAA").Select
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$BP$1005").AutoFilter Field:=1, Criteria1:="Manager"
ActiveSheet.Range("$A$1:$BP$1005").AutoFilter Field:=67, Criteria1:=Range("BP1").Value

The First will always produce a result, because there is a "Manager" always a manager for every retail store, but the second filter (a department filter), filters from those managers according to the department selected in cell "BP1". However, not every department has a Manager, so when it trys to filter on the value BP1, there may not be any results found, so it just displays everything.

Is there away I can say that if the value in BP1 does not exist in the column (Autofilter Field 67) then don't perform the the second filter?

Many Thanks,

Cris
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Does this work for you

Code:
Sub filtermacro()
    Dim found
    Sheets("AAA").Select
    ActiveSheet.Range("$A$1:$BP$1005").AutoFilter Field:=1, Criteria1:="Manager"
    On Error GoTo errhandler
    found = Range("BO:BO").Find(Range("BP1").Value, Range("BO1")).Row
    ActiveSheet.Range("$A$1:$BP$1005").AutoFilter Field:=67, Criteria1:=Range("BP1").Value
errhandler:
    Exit Sub
End Sub

Autofilter field 67 is column BO, right? If it isn't change as necessary
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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