auto filter by two criteria

bluepenink

Well-known Member
Joined
Dec 21, 2010
Messages
585
hello this is my macro to filter by town, however i want to also filter by invoice type.....i dont know how to add the other criteria

town name = D51 -cook county worksheet
invoice type = D52 - cook county worksheet

the raw data, where i want data to be filter contains the town name in column D and invoice type in column F...the worksheet is called "Chicago-2011"

this is my current macro that sorts by only town D51

Code:
Private Sub Worksheet_BeforeDoubleclick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Target, Range("D54:D68")) Is Nothing Then
        Cancel = True
        Range("D51") = Target.Offset(, -1).Value
    End If
End Sub

this is the macro on "chicago-2011" worksheet (see below)
Code:
Option Explicit
Private Sub Worksheet_Activate()
    With Me
      .Unprotect Password:="analyst"
      .AutoFilterMode = False
      .Range("MyHeaders").AutoFilter
      .Protect Password:="analyst", UserInterfaceOnly:=True, _
                                    AllowFormattingCells:=True, _
                                    Contents:=True, Scenarios:=True, _
                                    AllowFormattingColumns:=True, _
                                    AllowFormattingRows:=True, _
                                    AllowFiltering:=True
    End With
End Sub

can someone pls help...thx u so much
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi,

Assuming Town Name as Field1 and Invoice Type as Field2 (ie, 1st and 2nd columns in range MyHeaders), maybe something like

Code:
 With .Range("MyHeaders")
            .AutoFilter
            .AutoFilter Field:=1, Criteria1:=Range("D51").Value
            .AutoFilter Field:=2, Criteria1:=Range("D52").Value
End With

HTH

M.
 
Upvote 0
oops...

the criteria ranges are in Cook County worksheet, so

Code:
With .Range("MyHeaders") 
            .AutoFilter
            .AutoFilter Field:=1, Criteria1:=Sheets("Cook County").Range("D51").Value
            .AutoFilter Field:=2, Criteria1:=Sheets("Cook County").Range("D52").Value 
End With
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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