Hello,
I'm very new to VBA so pardon me if I have a glaring mistake somewhere. I am currently trying to activate only one slicer button and deactivate all the other ones based on the slicer's caption. So, basically I would loop through the slicer Items and look for a particular phrase and deactivate all the items until I get a match. Unfortunately, I am getting a run-time 1004 error application-defined or object-defined error.
Here is my code:
I have noticed that the SlicerItems caption and value are the same which is a bit weird to me if that is relevant. Thanks a bunch for the help.
I'm very new to VBA so pardon me if I have a glaring mistake somewhere. I am currently trying to activate only one slicer button and deactivate all the other ones based on the slicer's caption. So, basically I would loop through the slicer Items and look for a particular phrase and deactivate all the items until I get a match. Unfortunately, I am getting a run-time 1004 error application-defined or object-defined error.
Here is my code:
Code:
Sub Test()
Dim sC As SlicerCache
Dim sL As SlicerCacheLevel
Dim sI As SlicerItem
Set sC = ThisWorkbook.SlicerCaches("Slicer_Name")
Set sL = sC.SlicerCacheLevels(1)
sC.ClearManualFilter
For Each sI In sL.SlicerItems
If sI.Caption = "Goal" Then
sI.Selected = True [I][B]<- error trips here[/B][/I]
Else
sI.Selected = False
End If
Next sI
End Sub
I have noticed that the SlicerItems caption and value are the same which is a bit weird to me if that is relevant. Thanks a bunch for the help.