Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88868

Count Elements Selected Within a Slicer

$
0
0

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!


Viewing all articles
Browse latest Browse all 88868


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>