I have a pivot table that shows Revenue, GM, Revenue vs Plan and GM vs Plan by Account.
I want users to have the ability to sort the table by clicking on each these columns.
To do this, I've decided to create 4 shapes (transparent) and place each of them above each of the data/value fields.
When they click on a field, it should call a macro and sort the pivot table based on that field.
There will be a default order, say descending and when they click on it again, it should do the reverse i.e. ascending.
Sorting can be done using code below but how do I check how the column is currently sorted? Based on that say if it is Ascending, sort by descending and vice-versa?
I'm open to any other suggestions to achieve the requirement too.
I want users to have the ability to sort the table by clicking on each these columns.
To do this, I've decided to create 4 shapes (transparent) and place each of them above each of the data/value fields.
When they click on a field, it should call a macro and sort the pivot table based on that field.
There will be a default order, say descending and when they click on it again, it should do the reverse i.e. ascending.
Sorting can be done using code below but how do I check how the column is currently sorted? Based on that say if it is Ascending, sort by descending and vice-versa?
I'm open to any other suggestions to achieve the requirement too.
Code:
Sub PivotTableSort1()
Dim PvtTbl As PivotTable
Set PvtTbl = Worksheets("Sheet1").PivotTables("PivotTable1")
PvtTbl.PivotFields("Account").AutoSort Order:=xlAscending, Field:="Sum of Revenue"
End Sub