Pramod
Pramod

Reputation: 1461

How to access Pivot Items of a Pivot Field which is present in Report Filter using VBA

I used the below code to print the Pivot Items present in Each PivotField and their visible status. I have 5 Pivot Fields in the Report Filter.

The problem is, it is fetching the no.of Pivot Fields Properly. But when it comes to the no.of Pivot Items is returning 0 for every pivot field. In real each Field has many items. I'm not trying to print the visible items. But Items and their Visible Status.

Dim pf As PivotField
Dim pt As PivotTable
Dim pi As PivotItem

Set pt = Sheets("Reasons").PivotTables("PivotFields")
For Each pf In pt.PageFields
     For Each pi In pf.PivotItems
         Debug.Print pi.Name & " : " & pi.Visible
     Next
Next

Upvotes: 0

Views: 1579

Answers (1)

jeffreyweir
jeffreyweir

Reputation: 4824

See my code at the below link that lets you sync PivotTables efficiently in the event that you can't use Slicers http://blog.contextures.com/archives/2012/08/28/update-specific-pivot-tables-automatically/

Upvotes: 1

Related Questions