I have several slicers within a spreadhseet. I\'d like to be able to loop over one of these via VBA, and select every option one by one. The macro below seems fine to my ti
I tried the above solutions but can't get them to work. I kept getting a 1004 object not defined error; might be because I'm using the data model. In the end I cobbled together this solution which picks up the slicer values from a range and then calls another macro to save in pdf (which was my ultimate objective). Not elegant but effective.
Sub looop()
Dim rng As Range, cell As Range
Set rng = Sheet1.Range("B4:B5")
For Each cell In rng
ActiveWorkbook.SlicerCaches("Slicer_MasterBrand").VisibleSlicerItemsList = Array("[Customer].[MasterBrand].&[" & cell.Value & "]")
a_ExportPDF
Next cell
End Sub