Molecheese
New Member
- Joined
- Jan 30, 2016
- Messages
- 5
- Office Version
- 365
- Platform
- Windows
Hi - I have a data slicer which I want to change based on the input to an individual cell (C1). The below code is doing that, but it leaves the previously selected option in the slicer too - what code do I need to add to 'reset' the values or deselect any other selected slicer options before selecting the new value. Apologies if this question is boring / simple - I'm very much a self-taught novice. Thanks in advance
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sc As SlicerCache
Dim si As SlicerItem
Set sc = ThisWorkbook.SlicerCaches("Slicer_Hole")
If Not Intersect(Target, [c1]) Is Nothing Then
If Target.Value = "(ALL)" Then
sc.ClearAllFilters
Else
For Each si In sc.SlicerItems
If Target.Value = si.Name Then
si.Selected = True
Else
si.Selected = False
End If
Next
End If
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sc As SlicerCache
Dim si As SlicerItem
Set sc = ThisWorkbook.SlicerCaches("Slicer_Hole")
If Not Intersect(Target, [c1]) Is Nothing Then
If Target.Value = "(ALL)" Then
sc.ClearAllFilters
Else
For Each si In sc.SlicerItems
If Target.Value = si.Name Then
si.Selected = True
Else
si.Selected = False
End If
Next
End If
End If
End Sub