Johnny C
Well-known Member
- Joined
- Nov 7, 2006
- Messages
- 1,069
- Office Version
- 365
- Platform
- Windows
I'm having trouble setting fields in VBA.
As part of seeing what is going on, I put in some code to loop through the pivot items in the pivot field and debug.print the values. It has done it, but the debug.print has generated the same list twice and one has blank as an option. Can anyone explain that, is it something do do with the pivotcache?
and this is what got printed (Months 3-12 removed)
As part of seeing what is going on, I put in some code to loop through the pivot items in the pivot field and debug.print the values. It has done it, but the debug.print has generated the same list twice and one has blank as an option. Can anyone explain that, is it something do do with the pivotcache?
VBA Code:
For Each pf In pt.PageFields
If pf.Name = "Month" Then
For Each pi In pf.PivotItems
Debug.Print ws.Name & "-" & pt.Name & "-" & pf.Name & "-" & pi.Name
Debug.Print pi.Visible
Next pi
and this is what got printed (Months 3-12 removed)
Rich (BB code):
Sales Summary (1)-PivotTable1-Month-1
True
Sales Summary (1)-PivotTable1-Month-2
True
Sales Summary (1)-PivotTable1-Month-1
True
Sales Summary (1)-PivotTable1-Month-2
True
Sales Summary (1)-PivotTable1-Month-(blank)
True