This is my first shot using VBA. I need to display slicer selections in excel spreadsheets. There are 15-20 slicers in each sheet, with up to 50 possible selections, so I do not want to use the cube code to display one selection in each cell. I'd like them all to be separated by comma in one cell if possible (or return "all" or "none").
Here is what I have pieced together through research on this site and others, as well as attempting to edit it myself (so it is likely a complete mess).
I'm giving up searching and asking for help! And if you can point me to a simple, "crash course" VBA basics site, I'd appreciate it as well. Thank you.
Public Function GetSlicerItems()
Dim cache As Excel.SlicerCaches
Set cache = ThisWorkbook.SlicerCaches("Slicer_YR_MNTH_CD1")
Dim sItm As Excel.SlicerItem
Dim ICt As Long
For Each sItm In cache.SlicerItems
If sItm.Selected = True Then GetSlicerItems = GetSlicerItems & sItm.Name & ", "
ICt = ICt + 1
If sItm.HasData = False Then
ICt = ICt + 1
End If
Next
If Len(GetSlicerItems) > 0 Then
If ICt = cache.SlicerItems.Count Then
GetSlicerItems = "All Items"
Else
GetSlicerItems = Left(GetSlicerItems, Len(GetSlicerItems) - 2)
End If
Else
GetSlicerItems = "No items selected"
End If
End Function