Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Insert a Refresh Button for a Pivot Table in Excel

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Excel has no built-in “refresh pivot table” button you can drop onto a sheet with one click, but you can create one in about a minute using a small recorded macro and a shape or form control. The button runs ActiveWorkbook.RefreshAll (or a specific pivot cache refresh), so every pivot table connected to that data updates on demand. You will need the workbook saved as an .xlsm macro-enabled file and Excel’s Developer tab visible. The steps below are for Excel on Windows desktop; the Mac ribbon labels differ slightly, and Excel for the web cannot run macros at all.

What You'll Need

  • Excel desktop for Windows or Mac (not Excel for the web, which cannot run VBA macros).
  • A workbook containing at least one pivot table, saved as .xlsm (macro-enabled) before you add the button.
  • The Developer tab enabled: File > Options > Customize Ribbon, tick Developer in the right-hand list, click OK. On Mac, Excel > Preferences > Ribbon & Toolbar.
  • Macro security set to allow macros with notification, so you can enable them when the file opens.

Step-by-Step

  1. Save the file as macro-enabled. Go to File > Save As, choose “Excel Macro-Enabled Workbook (*.xlsm)” from the file type dropdown, and save. If you skip this, Excel will strip the macro when you close the file and your button will stop working.
  2. Open the VBA editor. Press Alt+F11 (on Mac, Fn+Option+F11 or use the Developer tab > Visual Basic). The editor opens in a separate window.
  3. Insert a standard module. In the editor, click Insert > Module. A blank code pane appears under “Module1” in the Project Explorer.
  4. Paste the macro. Type or paste the following, replacing nothing unless you want to target a single pivot table:
    Sub RefreshPivots()
        ActiveWorkbook.RefreshAll
    End Sub
    RefreshAll refreshes every data connection and pivot cache in the workbook, which is usually what you want. If you only want one pivot table refreshed, use ActiveSheet.PivotTables(1).RefreshTable instead, but note that this refreshes only that pivot, not the underlying query.
  5. Close the editor. Press Alt+Q to return to Excel. Your macro now exists but has no button yet.
  6. Insert a shape or form control. On the Insert tab, click Shapes and pick a rounded rectangle, or use Developer > Insert > Form Controls > Button (Form Control). Draw it on the sheet near the pivot table.
  7. Assign the macro. Right-click the shape and choose Assign Macro (for a form control button, the Assign Macro dialog appears automatically when you draw it). Select RefreshPivots and click OK.
  8. Label the button. Right-click the shape, choose Edit Text, and type “Refresh Pivots”. Format the fill and font however you like.
  9. Test it. Change a value in the source data, then click the button. The pivot table should update immediately. If nothing changes, see Troubleshooting below.
  10. Save and reopen. Save the .xlsm file, close it, and reopen it. If a yellow security bar appears, click Enable Content. The button should work as before.

Common Mistakes

  • Saving as .xlsx. The macro is discarded on close, leaving a dead button. Always use .xlsm.
  • Putting the code in a sheet module. If you paste the macro into “Sheet1” instead of a standard module, the Assign Macro list may not show it. Move the code to Insert > Module.
  • Assigning the wrong macro. If you have several macros, double-check the name in the Assign Macro dialog matches the one you wrote.
  • Expecting the button to refresh a pivot on another sheet. RefreshAll covers the whole workbook, but ActiveSheet.PivotTables(1) only covers the active sheet. Pick the version that matches your layout.
  • Forgetting to enable macros. A button that does nothing after reopening is usually blocked by the security bar. Click Enable Content, or add the file’s folder to Trusted Locations in File > Options > Trust Center.
  • Using Excel for the web. The browser version cannot run VBA, so the button will not work there. Use the desktop app.

Tips

  • Name the shape clearly (right-click > Edit Text) so anyone opening the file knows what it does.
  • If your pivot is based on an external data connection, RefreshAll also re-runs the query, which can take a moment on large datasets. Add a status message if the refresh is slow: put Application.StatusBar = “Refreshing…” before the refresh and reset it to False afterwards.
  • To refresh a single pivot table without touching others, use ActiveSheet.PivotTables(“PivotTable1”).RefreshTable, replacing the name with the one shown in PivotTable Analyze > PivotTable Name.
  • For a keyboard-only option, Alt+F5 refreshes all data in the workbook without any macro at all — useful if you only occasionally need a manual refresh.
  • Group related buttons on one row and lock their positions by protecting the sheet (Review > Protect Sheet) so users cannot drag them accidentally.

Troubleshooting

  • The button does nothing. Check the security bar at the top of the window and click Enable Content. Then right-click the shape and confirm the macro name is assigned.
  • “Cannot run the macro” error. The macro may have been removed when the file was saved as .xlsx, or macros are disabled by policy. Save as .xlsm and check File > Options > Trust Center > Macro Settings.
  • The pivot updates but shows old data. The pivot may be connected to a different data source than the one you edited. Click inside the pivot, go to PivotTable Analyze > Change Data Source, and confirm the range or table.
  • Refresh is very slow. Large external connections can take time. Consider refreshing only the specific pivot cache rather than RefreshAll, or move the source data to a Table so Excel can refresh more efficiently.
  • The button moves when you scroll. That is normal for a shape placed on the sheet. If you want it fixed, place it in the top rows and freeze panes, or use a form control anchored to a cell.
  • Mac users see different labels. The Developer tab and Assign Macro dialog exist on Mac Excel, but ribbon names and shortcuts differ. Use the Developer tab rather than keyboard shortcuts if Alt+F11 does not respond.

Frequently Asked Questions

Can I add a refresh button without using macros?

Not a clickable button, no. Excel’s built-in refresh shortcuts are Alt+F5 (refresh all) and Ctrl+Alt+F5 (refresh the selected pivot), and you can add Refresh All to the Quick Access Toolbar via File > Options > Quick Access Toolbar. That gives you a toolbar icon, but not a button on the sheet itself.

Will the button work if I email the file to someone?

Yes, provided they open it in desktop Excel and click Enable Content when prompted. Excel for the web will not run the macro, so the button will appear but do nothing there.

Does the button refresh every pivot table in the workbook?

With ActiveWorkbook.RefreshAll, yes — every pivot cache and data connection refreshes. If you only want one pivot, use the single-pivot version of the macro shown in the steps.

Why did my button stop working after I saved?

The most common cause is saving as .xlsx, which removes macros. Re-save as .xlsm and reassign the macro if needed.

Can I make the button refresh automatically when the file opens?

Yes, but it requires a different approach: put ThisWorkbook.RefreshAll in the workbook’s Open event in the VBA editor. That refreshes on open without any button, and can be combined with the manual button for on-demand updates.

Does this work in Excel for Mac?

The VBA code and Assign Macro feature exist in desktop Excel for Mac, though ribbon labels and shortcuts differ. Excel for the web and most mobile versions cannot run macros, so the button will not function there.