I'm trying to write a macro that looks up the data fields in a pivot table, and if it finds any then removes them. It works fine when there's no calcualted fields present, but if there are calculated fields present then it bombs out. I think this is because calculated fields cannot be turned off (xlhidden) but need to be deleted. Any ideas. The ffg code works for removing datafields that are not calculated fields:
Dim pf As PivotField, PT As PivotTable
Set PT = ActiveSheet.PivotTables("PivotTable1")
For Each pf In PT.DataFields
pf.Orientation = xlHidden
Next pf
Dim pf As PivotField, PT As PivotTable
Set PT = ActiveSheet.PivotTables("PivotTable1")
For Each pf In PT.DataFields
pf.Orientation = xlHidden
Next pf