Sort Pivot table based on subtotal

Wong Chui Ching 1 Reputation point
2022-04-19T05:15:05.64+00:00

When I search for

PivotField.AutoSort

method: excel.pivotfield.autosort, there is a Parameter called CustomSubtotal.

Anyone have the sample, what should I put in for this parameter?

Here the sample table KH0d6.png

The main objective is use vba to autosort PivotTable based on "C Total".

From eCMQj.png to pVv8h.png

I had tried both code below, cannot work.

With pvt  
 .PivotFields("Field 1").AutoSort(Order:=Excel.XlSortOrder.xlDescending, Field:="Field 2", CustomSubtotal:="C Total")  
End With  
  
With pvt  
 .PivotFields("Field 1").AutoSort(Order:=Excel.XlSortOrder.xlDescending, Field:="Field 2", CustomSubtotal:="C")  
End With  

Thanks.

Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Wong Chui Ching 1 Reputation point
    2022-04-19T06:25:50.023+00:00
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.