loop through pivottables columns and rows

H

hpham77

I have a pivot table that have 2 columns that I need to loop through
and read both columns and each items of each columns...the pivotitems
only allow reading one column...does anyone know how to
programmatically read both columns?


Thanks
 
D

Debra Dalgleish

You can loop through the column fields and their items:

Sub test()
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = ActiveSheet.PivotTables(1)

For Each pf In pt.ColumnFields
For Each pi In pf.PivotItems
Debug.Print pf.Name & " - " & pi.Name
Next pi
Next pf

End Sub
 
Top