Check all autofilter

288enzo

Board Regular
Joined
Feb 8, 2009
Messages
98
Office Version
  1. 2016
Platform
  1. Windows
I've been making a lot of headway and am quite proud of myself with VBA (insert smiley face here). I have a dropdown, and based on the selection will autofilter a few different tables. What I'm trying to do now is basically unfilter by checking all options if "all" is in B1.

This is what I have so far, but ActiveSheet.ShowAllData is coming back with a 1004 run-time error. ShowAllData method of Worksheet class failed.

I'm running with Office 2016, sure wish our company would spring for 365. I saw 365 gets a filter function, so jealous.

VBA Code:
Sub filtermultiple()

With Worksheets("Sheet3").Range("A4")
.AutoFilter Field:=3, Criteria1:=Cells(1, 2).Value
.AutoFilter Field:=4, Criteria1:="New York"
End With
With Worksheets("Sheet3").Range("A2507")
.AutoFilter Field:=3, Criteria1:=Cells(1, 2).Value
.AutoFilter Field:=4, Criteria1:="California"
End With
With Worksheets("Sheet3").Range("A5010")
.AutoFilter Field:=3, Criteria1:=Cells(1, 2).Value
.AutoFilter Field:=4, Criteria1:="Texas"
End With
If Range("B1").Value = "All" Then
    ActiveSheet.ShowAllData
End If

End Sub
 

Some videos you may like

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

288enzo

Board Regular
Joined
Feb 8, 2009
Messages
98
Office Version
  1. 2016
Platform
  1. Windows
Figured a way to accomplish it.

VBA Code:
Sub filtermultiple()

With Worksheets("Sheet3").Range("A4")
.AutoFilter Field:=3, Criteria1:=Cells(1, 2).Value
.AutoFilter Field:=4, Criteria1:="New York"
End With
With Worksheets("Sheet3").Range("A2507")
.AutoFilter Field:=3, Criteria1:=Cells(1, 2).Value
.AutoFilter Field:=4, Criteria1:="California"
End With
With Worksheets("Sheet3").Range("A5010")
.AutoFilter Field:=3, Criteria1:=Cells(1, 2).Value
.AutoFilter Field:=4, Criteria1:="Texas"
End With

If Range("B1").Value = "All" Then
    ActiveSheet.Range("A4").AutoFilter Field:=3
    ActiveSheet.Range("A4").AutoFilter Field:=4
    ActiveSheet.Range("A2507").AutoFilter Field:=3
    ActiveSheet.Range("A2507").AutoFilter Field:=4
    ActiveSheet.Range("A5010").AutoFilter Field:=3
    ActiveSheet.Range("A5010").AutoFilter Field:=4
End If

End Sub
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,127,107
Messages
5,622,780
Members
415,927
Latest member
vedasinternational

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
Top