I am trying to implement functionality such that when a user double click the header in a pivot table, it will sort the pivot table by value in that header. The sorting order should toggle between ascending and descending on each double-click.
I have the code to sort it by one of the columns but can't figure out how to make it generic so that the code knows which column was clicked and sort accordingly.
Specifically, need to know how to determine PivotLine Item number (marked in Red below) based on what was clicked. Hopefully and easy way instead of doing math between column numbers and determining the item number.
I have the code to sort it by one of the columns but can't figure out how to make it generic so that the code knows which column was clicked and sort accordingly.
Specifically, need to know how to determine PivotLine Item number (marked in Red below) based on what was clicked. Hopefully and easy way instead of doing math between column numbers and determining the item number.
Code:
pvtTbl.PivotFields("Category A").AutoSort xlAscending _
, "Sum of Cash", pvtTbl.PivotColumnAxis.PivotLines(4), 1