CAN VBA SORT PIVOT TABLE BY ANOTHER FIELD VALUE?

nitrammada

Board Regular
Joined
Oct 10, 2018
Messages
78
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,
Does anyone know how to sort a field (Descriptions) by another field (Sort) in a pivot table without having to place the field (Sort) in the 'Rows' or 'Values' box? Can this be done with VBA?

To explain:
The field (Descriptions) has 1000's of rows so sorting by custom list will not work coupled with the fact that each report has different descriptions in differing order.
Sorting A-Z will not work as the sequence I want the Descriptions to appear, is not alphabetical.

I have indexed each Description with a field called ‘Sort’ which is essentially a row number, this is the order I need the descriptions to appear in. If put the design of the pivot table in Tabular Form, and insert the field (Sort) as a row, then yes, I can sort by that column and get something like this with the Descriptions in the correct order:
H1DescH2DescH3DescH5DescH6DescSortDescriptionsUnitQuantity
NEUTRAL BAYCLIENT COSTS%0.08
COMMERCIAL9.00
ESCALATION%0.07
EXPECTED %0.04
NET TRADEBASEMENTCEILINGFalse Ceilings 556021Note: CON101 - Note0.00
556022Basement 10.00
556023CLG-102 - 13mm m225.00
556024Insulation to sm225.00
556025450x450mm AccesNo1.00

Without the Sort field in the pivot table, I get this:
H1DescH2DescH3DescH5DescH6DescDescriptionsUnitQuantity
NEUTRAL BAYCLIENT COSTS%0.08
NEUTRAL BAYCOMMERCIAL9.00
ESCALATION%0.07
EXPECTED %0.04
NET TRADEBASEMENTCEILINGFalse Ceilings 450x450mm AccesNo1.00
Basement 10.00
CLG-102 - 13mm m225.00
Insulation to sm225.00
Note: CON101 - Note0.00

You can see above, the order of the Descriptions field is incorrect.

I need the layout in 'Compact Form', however, when I change to 'Compact Form' I get a result like this:
Row LabelsUnitQuantityRateTotal
NEUTRAL BAY PROJECT
CLIENT COSTS%0.0845,753,0893,660,247
COMMERCIAL IMPACT AS ADVISED BY CLIENT9.007,00021,000
ESCALATED TRADE VALUE%0.0785,519,7932,993,193
EXPECTED CONSTRUCTION TENDER AMOUNT%0.0455,258,9342,210,357
NET TRADE VALUE
BASEMENT
CEILING
False Ceilings
556021
Note: CON101 - Note0.0000
556022
Basement 10.0000
556023
CLG-102 - 13mm m225.00852,125
556024
Insulation to sm225.0035875
556025
Note: CON101 - No1.00450450

You can see above, that the Sort field occupies a row. Even if I hide the field in Tabular Form and then change to Compact Form, the Sort field still occupies a row, except that it’s blank. I have tried with changing the height of the row to 1, and it looks ok, but it’s a cumbersome way to do it and as I’m designing this pivot table for 100’s of end users, it can’t be this complex.

What I'm after is a report like this.
1639617304397.png


Is there any way of achieving this with perhaps, VBA? Where the VBA code will sort the 'Descriptions' field by the 'Sort' field, as custom list and A-Z sorting will not achieve the above.
I would be very grateful for any thoughts or suggestions you may have.
Thanks in advance
Adam
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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