larry the fish
larry the fish

Reputation: 1

Auto filter 2 columns

I have command buttons to auto filter, the first and second work, the third doesn't, I want to filter by two criteria and two columns. Any ideas?

    Private Sub CommandButton6_Click()
    Worksheets("Sheet1").Range("K4 : K1900").AutoFilter _
    Field:=1, _
    Criteria1:="No", _
    VisibleDropDown:=False
    End Sub
    Private Sub CommandButton7_Click()
    Cells.AutoFilter
    End Sub
    Private Sub CommandButton8_Click()
    Worksheets ("Sheet1")
        .Range("K4:K1900").AutoFilter
        .Range("C4:C1900").AutoFilter
        Field:=1,
        Criteria1:="No", _
        Criteria1:="City",_
        VisibleDropDown:=False
    End Sub

Upvotes: 0

Views: 110

Answers (1)

Subodh Tiwari sktneer
Subodh Tiwari sktneer

Reputation: 9976

You may try it like this...

Private Sub CommandButton8_Click()
    With Worksheets("Sheet1").Range("C4:K1900")
        .AutoFilter field:=9, Criteria1:="No"       'field:=9 means the 9th column in the filtered range
        .AutoFilter field:=1, Criteria1:="City"     'field:=1 means the 1st column in the filtered range
    End With
End Sub

Upvotes: 1

Related Questions