Using VBA to change PivotTable field view/function

karl04

New Member
Joined
Dec 15, 2004
Messages
6
I have a pivot table in my workbook. I would like to change the PivotTable Field function to VarP using a macro but receive an error when it runs.
I recorded the macro and then tried to run the code but the following error appears:
"Unable to get the PivotFields property of the PivotTable class"

The code given by the recorder is:
Code:
Range("A3").Select
         ActiveSheet.PivotTables("PivotTable1").PivotFields("Varp of Full Cost"). _
         Function = xlVarP

I need to change to the variance so that I can check for any discrepancies (i.e. if variance is not 0 then there is a problem)

I hope some can help or suggest any easier way to perform this.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

karl04

New Member
Joined
Dec 15, 2004
Messages
6
To answer my own question.....

You can use the following code to set the function of a Pivot Table where the top left-hand cell of the table is A3.

Code:
Range("A3").Select
ActiveCell.PivotField.Function = xlVarP

Replace xlVarP with whatever function you wish to use such as - xlSum, xlCount or xlAverages.
 

Forum statistics

Threads
1,147,845
Messages
5,743,513
Members
423,801
Latest member
paulj4177

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top