Move DataField in Pivot Table with VBA

dgrimm

Board Regular
Joined
Sep 17, 2007
Messages
159
I am trying to move a DataField to the beginning of the data fields. However when I try recording a macro it has a completely different field in the coding and says that it is adding the data field. So what I am trying to do is move "AGE" to be the first data field in the datafield list. I have tried clicking on it in the field list box and selecting move to beginning but that is giving the above code. Anyone have any ideas.

Thank you

Dave
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
without any of your code, I can give you hints but you will need to fit it in the code.

I think what you want is the .Position property of the pivotField. I know this works for ordering the row and column fields. I have never needed to do it with the value fields.

Code:
        With .PivotFields("AGE")
            .Orientation = xlDataField
            .Position = 1
            .Calculation = xlNoAdditionalCalculation
        End With
 
Upvote 0
You are welcome. Thanks for letting me know it helped.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,492
Members
448,967
Latest member
visheshkotha

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