Apply filter to certain worksheets

LUIS FREUND
LUIS FREUND used Ask the Experts™
on
I have this code that applies a filter across the whole workbook.  Wanted to modify it only apply to certain worksheets within the workbook.  I have a worksheet named "DEMAND" and "LOCATION", these are the worksheets I would want the filter to be applied to.  Here is the code I have:

Sub FilterJan()

    Dim xWs As Worksheet
    On Error Resume Next
    For Each xWs In Worksheets
        xWs.Range("A1").AutoFilter 2, "=Jan"
    Next
End Sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mechanical Engineer
Most Valuable Expert 2013
Top Expert 2013
Commented:
Sub FilterJan()

    Dim xWs As Worksheet
    On Error Resume Next
    For Each xWs In Worksheets
        Select Case UCase(xWs.Name)
        Case "DEMAND", "LOCATION"
                xWs.Range("A1").AutoFilter 2, "=Jan"
         End Select
    Next
End Sub

Open in new window

Author

Commented:
Hell Yeah!   Awesome...thank you very much Byundt

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial