• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to stop VBA changing the sort order

Christof

Member
Hi, hopefully a quick one..
Is there something I can add my VBA to stop the pivot table that it is in from resorting

Code:
        pt4.DataFields(1).Orientation = xlHidden
        pt4.PivotFields(sumField).Orientation = xlDataField


pt4 is the PivotTable shown
"sumfield" is either "Pax" or "Revenue" as I want to be able to select between the two, but when it changes it resorts it.
Basically, whatever it's a "Sum of.." needs to be sorted Largest to Smallest on the Grand Total.

upload_2018-11-27_13-2-1.png
 
Just add sorting operation to your code.

Each time you set different field orientation, sort is reset. As Pivot sorting is dependent on context.

To get general syntax of sorting on values. Use macro recorder and apply your sort operation manually.
 
Back
Top