Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
zenobendi
Contributor III
Contributor III

Sort a pivot table with macro button

I've a single pivot table whose ID is CH577 ("ANALISI MARGINE") and I have some buttons that open it. The tab has many different columns and I want to order it by pressing buttons. So for example if I press button 1 it will sort my tab for column 1, if I press button 2 it will sort my tab for column 2 ecc.

Is there any macro I could use or something like that?

Because I've tried this macro:

Sub SortChart

Set ch = ActiveDocument.GetSheetObject("CH577")
ch.SortBy 17
End Sub

But when I press the button it opens the tab but it doesn't run the macro, instead it opens Edit Module

Thanks

1 Solution

Accepted Solutions
Claudiu_Anghelescu
Specialist
Specialist

Try this:

Sub SortChart

Set chart1 = ActiveDocument.GetSheetObject("CH577")
chart1.SortBy 17

End Sub
To help community find solutions, please don't forget to mark as correct.

View solution in original post

1 Reply
Claudiu_Anghelescu
Specialist
Specialist

Try this:

Sub SortChart

Set chart1 = ActiveDocument.GetSheetObject("CH577")
chart1.SortBy 17

End Sub
To help community find solutions, please don't forget to mark as correct.