Jan 20 2022 06:39 AM
Hi Guys,
Seems like I cannot use the following code, Could you pleas help? I am trying to write a code which changes the filter value in a Slicer based on a cell reference. The debug window highlights the line:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("YoY")
If Target.Address = "$C$1" Then
ActiveWorkbook.SlicerCaches("Slicer_Platform").ClearManualFilter
If sh.Range("C1") = "A" Then
With ActiveWorkbook.SlicerCaches("Slicer_Platform")
.SlicerItems("B").Selected = False
.SlicerItems("A").Selected = True
End With
ElseIf sh.Range("C1") = "B" Then
With ActiveWorkbook.SlicerCaches("Slicer_Platform")
.SlicerItems("B").Selected = True
.SlicerItems("A").Selected = False
End With
End If
End If
End Sub