ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Pivottable - Added calculated fields and now can't clear pivot (https://www.excelbanter.com/excel-programming/390443-pivottable-added-calculated-fields-now-cant-clear-pivot.html)

Andreww

Pivottable - Added calculated fields and now can't clear pivot
 
I have some code that modifies a pivot (changes dimensions and
measures)

It all worked well until I wrote some VB to calculate some new cols/
measures. They appear as they should in the field list so I know that
the code to add them works:

Sub add_to_pivot()
With Sheets("pivot").PivotTables(1)
.CalculatedFields.Add Name:="cust_spend", Formula:="=spend/
Count"
.CalculatedFields.Add Name:="cust_vis", Formula:="=vis/Count"
.CalculatedFields.Add Name:="cust_duration",
Formula:="=duration/Count"
End With
End Sub


When I try to run the code that manipulates the pivot I get "runtime
error 1004" "unable to set the orientation property of the pivotfield
class".

The Code that fails is as follows:

With PT
For Each pf In .VisibleFields
pf.Orientation = xlHidden
Next
End With

My understanding is that the above code removes all dims/measures from
the pivottable, which it does fine unless one of the calculated
measures is inlcuded in the code run.

Do I have to do anything to these calculated fields to get them
recognised in some way??

I noticed various references to "PT.ManualUpdate = true"... put this
in my code and the whole thing froze up.

Cheers

Andrew



All times are GMT +1. The time now is 06:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com