VBA Toggle off/on filter (can't use slicer as file too big)

Melimob

Active Member
Joined
Oct 16, 2011
Messages
395
Office Version
  1. 365
Hi

I have a table where I want to either show 'blanks' or show 'all'.

The below code just keeps it on showing blanks. Can anyone help to add a filter if not applied and then show all / just show blanks based on field 5?

many thanks in advance

Code:
Private Sub ToggleButton1_Click()


If ActiveSheet.AutoFilterMode = True Then
'autofilter is on...
ActiveSheet.AutoFilterMode = False
Else
'autofilter is not on...
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=5, Criteria1:=""
End If


End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
try this
Code:
Private Sub ToggleButton1_Click()
    On Error Resume Next
    Select Case ToggleButton1.Value
        Case True:  Me.ListObjects(1).Range.AutoFilter Field:=5, Criteria1:=""
        Case Else:  Me.ShowAllData
    End Select
End Sub
 
Upvote 0
try this
Code:
Private Sub ToggleButton1_Click()
    On Error Resume Next
    Select Case ToggleButton1.Value
        Case True:  Me.ListObjects(1).Range.AutoFilter Field:=5, Criteria1:=""
        Case Else:  Me.ShowAllData
    End Select
End Sub

thank you Yongle however I need to adjust that Me.ListObjects(1).Range.AutoFilter Field:=5, Criteria1:=Show all Data

so that it doesn't clear the other filters?

Do you know how I would do this please?

thank you!
 
Upvote 0
thank you Yongle however I need to adjust that Me.ListObjects(1).Range.AutoFilter Field:=5, Criteria1:=Show all Data

so that it doesn't clear the other filters?

Do you know how I would do this please?

thank you!

Its ok, I figured it out!!

Code:
Private Sub ToggleButton1_Click()
    On Error Resume Next
    Select Case ToggleButton1.Value
        Case True:  Me.ListObjects(1).Range.AutoFilter Field:=5, Criteria1:=""
        Case Else:  Me.ListObjects(1).Range.AutoFilter Field:=5
End SelectEnd Sub

thank you!!!
 
Upvote 0
thanks for posting your final solution
(y)
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,308
Members
449,152
Latest member
PressEscape

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