Not able to get code for sorting in pivot table

Hi,
I am getting error while running a vb activity.
And getting this error.
image
Can anyone help please?
@supermanPunch @ushu @Gokul001 @Anil_G
@shreyash_shirbhate

@Kunal_Jain can you post excel and vba code here?

Sub SortPivotColumn()
Dim PT As PivotTable
Set PT = ActiveSheet.PivotTables(“PivotTable6”)
With PT.PivotSelect(“Branch/Plant”)
.Orientation = xlLabelOnly
.SortOnValue = True
.SortOrder = xlAscending
End With
End Sub

I am sorry but I cannot share the excel sheet because it contain sensitive data.

  1. make sure your pivot table is the correct name i.e. PivotTable6. If its wrong, change name and run again
    image

  2. if the name is correct, try use this code instead

Sub SortPivotColumn()
Dim PT As PivotTable
Set PT = ActiveSheet.PivotTables("PivotTable6")
With PT
.PivotFields("Branch/Plant").Orientation = xlRowField 
.PivotFields("Branch/Plant").AutoSort xlAscending, "Branch/Plant" 
End With
End Sub

It had given me the desired output
Thank you!!

1 Like

no problem! good luck

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.