Check all autofilter

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
723
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
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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
 
Upvote 0
Solution

Forum statistics

Threads
1,215,459
Messages
6,124,947
Members
449,198
Latest member
MhammadishaqKhan

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