Option Explicit
Sub ListSlicerItems()
Dim i As Integer
With ActiveWorkbook.SlicerCaches("Slicer_Test")
For i = 1 To ActiveWorkbook.SlicerCaches("Slicer_Test").SlicerItems.Count
Range("B" & i) = .SlicerItems(i).Name
Next
End With
End Sub
Hi Mr Karr
The following will list all of the slicer items in your slicer.
Code:Option Explicit Sub ListSlicerItems() Dim i As Integer With ActiveWorkbook.SlicerCaches("Slicer_Test") For i = 1 To ActiveWorkbook.SlicerCaches("Slicer_Test").SlicerItems.Count Range("B" & i) = .SlicerItems(i).Name Next End With End Sub
Note if you right click on your slicer and choose Slicer settings you will get the name of the slicer which is important if you want to get the above coding to work.
View attachment 14571
I have attached a sample.
Take care
Smallman
Hi @Smallman :
It works fine. But can you please help to accommodate with this situation. I have 2 slicers with the same name. When I modify the above provided code, only one picks up & lists out the data but the other throws up an error. I think some data model & cube work at the background.
Can you please look into this. I have attached a file with screenshots and slicer values.
Thanks a lot for the help in advance.
Hi Mr Karr
The following will list all of the slicer items in your slicer.
Code:Option Explicit Sub ListSlicerItems() Dim i As Integer With ActiveWorkbook.SlicerCaches("Slicer_Test") For i = 1 To ActiveWorkbook.SlicerCaches("Slicer_Test").SlicerItems.Count Range("B" & i) = .SlicerItems(i).Name Next End With End Sub
Note if you right click on your slicer and choose Slicer settings you will get the name of the slicer which is important if you want to get the above coding to work.
View attachment 14571
I have attached a sample.
Take care
Smallman
Hi ,the code for listing the item in the slicer is very good but how can we retrieve only the Selected item from the slicer.
Sub Demo()
Dim ar
ar = ThisWorkbook.SlicerCaches("Segment_Number_item1").VisibleSlicerItemsList
For i = 1 To UBound(ar)
Debug.Print ar(i)
Next
End Sub