Pyr_Pressure
Pyr_Pressure

Reputation: 1

How to combine a Toggle Button and a Slicer for Filtering a Table

I have a table where I am attempting to combine a toggle button and a slicer to filter the content.

The table ("Data") is located on the worksheet "Timeline". The toggle button is to simply hide/show the entire list of species, or only species that were located in a "Program" area. The Slicer ("Slicer_Program") is to show data relevant to particular "Program" areas.

I need the filter in the table to update every time I use the toggle button to reflect what is selected in the slicer, and to update every time i use the slicer.

at the moment, if i have the slicer set to "Program A" and toggle the button to hide the species that were not found, It works fine. However, if i change the slicer to show data from "Program B", the species which were not found in A but were found in B remain hidden, and the species which were found in B but not A remain visible despite wanting them to be hidden. For it to work i need to toggle the button off and then back on every time i change the slicer setting.

Currently i have two toggle buttons using the code:

Private Sub ShowAll_Click()
Dim range_to_filter As Range
Set range_to_filter = Sheets("Timeline").Range("E5:E57")
range_to_filter.AutoFilter Field:=5, Criteria1:="<>"""
End Sub

Private Sub ShowPresent_Click()
Dim range_to_filter As Range
Set range_to_filter = Sheets("Timeline").Range("E5:E57")
range_to_filter.AutoFilter Field:=5, Criteria1:="<>0"
End Sub

to hide and show the relevant rows of data. I would prefer to have one button, and for it to automatically update every time the slicer selection is changed.

Upvotes: 0

Views: 86

Answers (0)

Related Questions