I have started to work on an excel sheet and to run some calculated field I need a public function that returns the number of items selected within a single slicer. I surfed the internet, but unfortunately I was only able to find VBA codes that actually do not work at all. I have started to work with VBA only recently for the first time, so I have no experience with it.
I managed to use this code, which however is not a public function, so it cannot be used within calculated fields in pivot tables:
Private Sub Worksheet_PivotTableChangeSync(ByVal Target As PivotTable)
Const sSlicerName As String = "Producer"
On Error Resume Next
If Not IsError(Target.Slicers(sSlicerName).Name) Then _
Range("A1") = ActiveWorkbook.SlicerCaches("Slicer_"& sSlicerName) _
.VisibleSlicerItems.Count
End Sub
Did any of you face this issue and find a way to solve the problem?
Thank you in advance!