Link to home
Create AccountLog in
Avatar of Andreas Hermle
Andreas HermleFlag for Germany

asked on

Sorting a pivot table on a specific data value field by means of a macro

Dear Experts,
I got a pivot table (MyPivotTable) to which I added a copy of the sales field to the values area of the pivot table to show values as a difference from the previous year.
I named this field 'Dev 20/21'

I now would like to do the sorting ...
... for the 'Dev 20/21'  values in descending order for the countries of EACH Sales Area
(Sales Area 01, 02, 03, 04) by means of a macro.
So the macro should do these tasks in one go.for all Sales Areas.

I tried to tweak a macro I recently got from Ejgil from EE for another task but I did not succeed in altering it.  

Sub Sort_Dev20_21()
ActiveSheet.PivotTables("PT_Overview").PivotFields("Land").AutoSort xlAscending _
    , "Dev 20/21", ActiveSheet.PivotTables("PT_Overview").PivotColumnAxis.PivotLines(1), 1
End Sub

Open in new window


Help is very much appreciated. I have attached a sample file for your convenience.

Regards, Andreas

Sort_Field_Dev_20_21.xlsm

User generated image
ASKER CERTIFIED SOLUTION
Avatar of Ejgil Hedegaard
Ejgil Hedegaard
Flag of Denmark image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account