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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,588
Members
449,089
Latest member
Motoracer88

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
Back
Top