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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,194
Messages
5,768,777
Members
425,492
Latest member
blueexcel123

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