Move DataField in Pivot Table with VBA

dgrimm

Board Regular
Joined
Sep 17, 2007
Messages
155
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
 

Some videos you may like

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

par60056

Well-known Member
Joined
Jul 26, 2012
Messages
1,581
Office Version
  1. 2011
  2. 2010
Platform
  1. Windows
  2. MacOS
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
 

par60056

Well-known Member
Joined
Jul 26, 2012
Messages
1,581
Office Version
  1. 2011
  2. 2010
Platform
  1. Windows
  2. MacOS
You are welcome. Thanks for letting me know it helped.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,509
Messages
5,596,568
Members
414,079
Latest member
Frills

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