troubleshooting Question

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

Avatar of Andreas Hermle
Andreas HermleFlag for Germany asked on
VBAMicrosoft ExcelMicrosoft Office
1 Comment1 Solution13 ViewsLast Modified:
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

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

Regards, Andreas


Ejgil Hedegaard

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros