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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
You could do them in reverse order and set the position to 1 for all of them.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,097
Messages
6,123,076
Members
449,094
Latest member
mystic19

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