Need help on slicers with OLAP data in Excel VBA

Spyridion

New Member
Joined
Dec 19, 2018
Messages
3
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:
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.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
So I found my answer. I just needed to add whatever sliceritem I needed into the VisibleSlicerItemList instead of using that for loop.
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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