• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Hide pivot calculated fields by VBA

Lolo

Member
Just to share the info (if already known, sorry :) )

I recently found a way to hide calculated fields from a pivot table via VBA

Previously the obvious instruction :
Set pt = ActiveSheet.PivotTables("mypivottable")
pt.pivotfields("my calculated field").Orientation = xlHidden
or
pt.CalculatedFields.Orientation = xlHidden

generated an error... And impossible to find a "simple" solution on the net.

ButI finally found this (Excel 2010).

Set pt = ActiveSheet.PivotTables("mypivottable")
For Each pi In pt.DataPivotField.PivotItems
pi.Visible = False
Next

This hide/remove all datafields and all calculated fields set in a pivot table, like it would be done manually

Hope this could helps someone.
 
Back
Top