Hey All!
Since Bakerman2 was kind enough to solve one of my long-running problems with the dashboard I'm working on, I have another to ask the community.
With the following code, I am able to capture the selected slicer filters and have them update in a cell on my sheet in real time.
My problem is that I have four slicers I want to do this with (each slicer's filters writing to a different cell), and I have not determined the way to do so yet.
My slicer names are: Slicer_Month, Slicer_TWP_Code, Slicer_Activity_Code, Slicer_Program_Code.
The cell formula for the first slicer would be:
Formula:
=GetSelectedSlicerItems("Slicer_Month")
The Public function that makes it possible is:
Public Function GetSelectedSlicerItems(SlicerName As String) As String
Dim oSc As SlicerCache
Dim oSi As SlicerItem
Dim lCt As Long
On Error Resume Next
Application.Volatile
Set oSc = ThisWorkbook.SlicerCaches("Slicer_Month")
If Not oSc Is Nothing Then
For Each oSi In oSc.SlicerItems
If oSi.Selected Then
GetSelectedSlicerItems = GetSelectedSlicerItems & oSi.Name & ", "
lCt = lCt + 1
ElseIf oSi.HasData = False Then
lCt = lCt + 1
End If
Next
If Len(GetSelectedSlicerItems) > 0 Then
If lCt = oSc.SlicerItems.Count Then
GetSelectedSlicerItems = "All Available Data Selected"
Else
GetSelectedSlicerItems = Left(GetSelectedSlicerItems, Len(GetSelectedSlicerItems) - 2)
End If
Else
GetSelectedSlicerItems = "No items selected"
End If
Else
GetSelectedSlicerItems = "No slicer with name '" & SlicerName & "' was found"
End If
End Function
I tried repeating this function four times with the slicer names but that resulted in Ambiguous name errors. I also tried inputting multiple slicer names into the slicercaches area of the sheet but that also did not work.
Any thoughts from my Excel Forum Heroes?
Bookmarks