PivotTable Fields positioning - VBA required

krshnn

New Member
Joined
Mar 23, 2022
Messages
17
Office Version
  1. 2013
Platform
  1. Windows
I have around 6 Columns in PivotTable namely 0-30 days, 31-60 days, 61-90 days, 91- 120 days, 121-150 days, 151-180 days
Thing is I want to have 0-30 in 1st position, 31-60 days in 2nd position and so.
Simple thing which I write is
ActiveSheet.PivotTables("PivotTable12").PivotFields("0-30 days").position = 1,
ActiveSheet.PivotTables("PivotTable12").PivotFields("31-60 days").position = 2 and so in chronological order

But the issue is there are times when 31-60 days / 61-90 days /or any one or more of the above column field may not be present at all.
i..e, there might be only two fields in those scenario say , 61-90 days and 91-120 days (then 61-90 days should be first and 91-120 days should be second).
In the above scenario, my position (due to aforementioned VBA code) gets jumbled up.

So basically I want a PivotTable.pivotfield position for all scenarios in chronological order (either all six of them are present or in cases where less than 6 are present)
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
You could do them in reverse order and set the position to 1 for all of them.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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