How to count the visible items in a specific field of PivotTable without looping through all the items?
The code:
ActiveSheet.PivotTables(1).PivotFields("MyFieldName").PivotItems.Count
returns the total number of items, no matter if they are selected or not.
I am looking for something like:
ActiveWorkbook.SlicerCaches(1).VisibleSlicerItems.Count
Update. I want to count how many items are selected in [Country] field of the picture below:

(I burglared the picture from: http://peltiertech.com/referencing-pivot-table-ranges-in-vba/ Hope, Jon won't mind it.)
I know this is an old question, but here is a simple solution
ActiveSheet.PivotTables(1).PivotFields("MyFieldName").VisibleItems.Count
I needed this for a report automation project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With