VBA autofilter based on cell contents

Rseq2

New Member
Joined
Sep 15, 2014
Messages
1
Hello,

I'm trying to sort a table based on a drop-down menu in cell F2. The below code I found online works great, except when I change the drop-down to "all" I need it to show all records and it currently filters for text "all". Any thoughts? I feel like this is a quick fix- just can't quite figure it out...

Private Sub Worksheet_Change(ByVal Target As Range)
If (Intersect(Target, Range("F2")) ="All") _
Then
Exit Sub
End If
Cells.AutoFilter Field:=6, Criteria1:="=" & Range("F2")
End Sub

Thanks!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Possibly...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("F2")) = "All" _
       Then
        ActiveSheet.ShowAllData
    Else
        Cells.AutoFilter Field:=6, Criteria1:="=" & Range("F2")
    End If
End Sub

or strictly speaking

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("F2")) = "All" _
       Then
        Cells.AutoFilter Field:=6
    Else
        Cells.AutoFilter Field:=6, Criteria1:="=" & Range("F2")
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,535
Messages
6,055,964
Members
444,839
Latest member
laurajames

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