Pivottable - Added calculated fields and now can't clear pivot

A

Andreww

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
 

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

Top