Avatar of Andreas Hermle
Andreas Hermle
Flag 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


VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Ejgil Hedegaard

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ejgil Hedegaard

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23