loop through pivottables columns and rows

  • Thread starter Thread starter hpham77
  • Start date Start date
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top