Forum Discussion
Pierre Gerrits
Feb 09, 2017Copper Contributor
Create a button to refresh pivot tables in a file
I have a large data query file with a few sheets containing pivot tables. I need to add a button to the first sheet that will refresh all the pivot tables in the file.
Haytham Amairah
Feb 10, 2017Silver Contributor
Dear Pierre,
First and foremost, add the (Developer Tab) to your Excel Ribbon, and follow these steps:
- Go to Insert at the Developer Tab, and click on it.
- You will find two sections: Forms Controls and ActiveX Control, in the ActiveX Control Section, select the command button, and add it to your sheet.
- Double click on the button, to open the VBA Editor, but before that, make sure that the design mode is turned on.
- Copy this command, and paste it in the VBA editor:
ActiveSheet.PivotTables("Your Pivot Table Name").PivotCache.Refresh |
So it would look as follows:
- Add your pivot table name to the code, and save it.
- Close VBA Editor
- Turn Design Mode off
- You have to save your workbook in one of these formats: (XLSM, XLSB, XLS), in order to save Refresh code.
Enjoy :)