Trying to understand PIVOT TABLE pivot fields order, and change?

logandiana

Board Regular
Joined
Feb 21, 2017
Messages
107
What determines the order of the columns headings from left to right? In this example it appears to be alphabetical, but is that always the case? Is there any set rule to this? Could have sworn I'd seen an example where this wasn't the case before.
Is there a way to change the order using VBA?


[TABLE="width: 478"]
<tbody>[TR]
[TD]Sum of Number
[/TD]
[TD]Color
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date
[/TD]
[TD]blue
[/TD]
[TD]green
[/TD]
[TD]orange
[/TD]
[TD]red
[/TD]
[TD]yellow
[/TD]
[TD]Grand Total
[/TD]
[/TR]
[TR]
[TD="align: right"]10/2/2017
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]11
[/TD]
[TD][/TD]
[TD="align: right"]11
[/TD]
[/TR]
[TR]
[TD="align: right"]10/3/2017
[/TD]
[TD="align: right"]17
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]17
[/TD]
[/TR]
[TR]
[TD="align: right"]10/4/2017
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]14
[/TD]
[TD][/TD]
[TD="align: right"]14
[/TD]
[/TR]
[TR]
[TD="align: right"]10/5/2017
[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]16
[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]16
[/TD]
[/TR]
[TR]
[TD="align: right"]10/6/2017
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]11
[/TD]
[TD="align: right"]11
[/TD]
[/TR]
[TR]
[TD="align: right"]10/7/2017
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]10
[/TD]
[TD="align: right"]10
[/TD]
[/TR]
[TR]
[TD="align: right"]10/8/2017
[/TD]
[TD="align: right"]14
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]14
[/TD]
[/TR]
[TR]
[TD="align: right"]10/9/2017
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]14
[/TD]
[TD][/TD]
[TD="align: right"]14
[/TD]
[/TR]
[TR]
[TD="align: right"]10/10/2017
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]17
[/TD]
[TD="align: right"]17
[/TD]
[/TR]
[TR]
[TD="align: right"]10/11/2017
[/TD]
[TD][/TD]
[TD="align: right"]13
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]13
[/TD]
[/TR]
[TR]
[TD="align: right"]10/12/2017
[/TD]
[TD][/TD]
[TD="align: right"]16
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]16
[/TD]
[/TR]
[TR]
[TD="align: right"]10/13/2017
[/TD]
[TD][/TD]
[TD="align: right"]19
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]19
[/TD]
[/TR]
[TR]
[TD="align: right"]10/14/2017
[/TD]
[TD][/TD]
[TD="align: right"]13
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]13
[/TD]
[/TR]
[TR]
[TD="align: right"]10/15/2017
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]15
[/TD]
[TD][/TD]
[TD="align: right"]15
[/TD]
[/TR]
[TR]
[TD="align: right"]10/16/2017
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]17
[/TD]
[TD="align: right"]17
[/TD]
[/TR]
[TR]
[TD="align: right"]10/17/2017
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]17
[/TD]
[TD="align: right"]17
[/TD]
[/TR]
[TR]
[TD="align: right"]10/18/2017
[/TD]
[TD="align: right"]13
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]13
[/TD]
[/TR]
[TR]
[TD="align: right"]10/19/2017
[/TD]
[TD="align: right"]10
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]10
[/TD]
[/TR]
[TR]
[TD="align: right"]10/20/2017
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]11
[/TD]
[TD][/TD]
[TD="align: right"]11
[/TD]
[/TR]
[TR]
[TD="align: right"]10/21/2017
[/TD]
[TD="align: right"]10
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]10
[/TD]
[/TR]
[TR]
[TD="align: right"]10/22/2017
[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]12
[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]12
[/TD]
[/TR]
[TR]
[TD]Grand Total
[/TD]
[TD="align: right"]64
[/TD]
[TD="align: right"]61
[/TD]
[TD="align: right"]28
[/TD]
[TD="align: right"]65
[/TD]
[TD="align: right"]72
[/TD]
[TD="align: right"]290
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
By default it will be alphabetical but you can sort it pretty much any way you want, including an entirely manual order, either in VBA or in Excel itself. How are you trying to sort it?
 
Upvote 0
This was just an example, but lets say I'd like to use VBA to sort it in a specific order bases on names. For instance lets say I always want the order Red, Orange, Yellow, Green, Blue.
 
Upvote 0
You don't actually need VBA for that. If you create a custom list in that order, you can sort the field using that list.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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