Pivot Table Automatic Refresh: Step-by-Step Guide
In this article
To make a pivot table refresh automatically, the most reliable method is to attach a short VBA macro to the worksheet's Change event so the pivot updates whenever source data changes. Excel has no built-in "refresh on change" checkbox; the alternative is to set the pivot to refresh when the workbook opens, which only updates once per session. This guide covers both approaches, plus the manual refresh shortcut and the mistakes that stop automatic refresh from working.
What You'll Need
- Excel for Windows or Mac (the VBA steps below are written for Windows; Mac menus differ slightly).
- A pivot table already built from a source range or Excel Table.
- The workbook saved as .xlsm (macro-enabled) if you use the VBA method.
- Permission to enable macros on your machine. If macros are blocked by policy, use the workbook-open refresh option instead.
Step-by-Step
- Decide which refresh method fits your need. Use the VBA method if you want the pivot to update the moment you edit the source data. Use the workbook-open method if you only need fresh numbers when the file is opened. Use manual refresh (Alt+F5 on Windows, or right-click the pivot and choose Refresh) for occasional updates.
- Convert your source range to an Excel Table. Select any cell in the source data and press Ctrl+T (Windows) or Command+T (Mac), confirm the range, and tick "My table has headers." Tables expand automatically when you add rows, so the pivot's source range grows with the data. Without a Table, new rows typed below the original range are ignored until you change the source range manually.
- Point the pivot at the Table. Click inside the pivot, go to PivotTable Analyze > Change Data Source, and enter the table name (for example, Table1) or select the whole table. Click OK. If the pivot was built from a plain range, this step is what makes future rows count.
- For the workbook-open method, open the pivot options. Right-click the pivot table, choose PivotTable Options, go to the Data tab, and tick "Refresh data when opening the file." Click OK. Save the workbook. The pivot now refreshes each time the file is opened, but not while it is open.
- For the VBA method, open the VBA editor. Press Alt+F11 (Windows). In the Project pane, find your workbook, expand it, and double-click the worksheet that holds the source data. The code window for that sheet opens.
- Paste the refresh macro. In the code window, enter a Worksheet_Change event that refreshes all pivot tables on the sheet. A minimal version is: Private Sub Worksheet_Change(ByVal Target As Range) followed by ThisWorkbook.RefreshAll on the next line, then End Sub. If you have several pivots and only want one refreshed, use the pivot's name with PivotTables("PivotTable1").PivotCache.Refresh instead of RefreshAll. Note that labels and exact object names vary by Excel version, so check the pivot name in PivotTable Analyze > PivotTable Name.
- Turn off background refresh for that pivot if the macro seems slow or inconsistent. Right-click the pivot, choose PivotTable Options, Data tab, and clear "Enable background refresh." This forces the refresh to finish before Excel continues, which makes the Change event behave predictably.
- Save as .xlsm and test. Use File > Save As and choose Excel Macro-Enabled Workbook. Close and reopen the file, enable macros when prompted, then type a new value into the source table. The pivot should update within a second or two.
- If you cannot use macros, fall back to the open-refresh setting and a manual shortcut. Keep "Refresh data when opening the file" ticked and press Alt+F5 (Windows) or use the Refresh button on the PivotTable Analyze tab whenever you need current figures during a session.
Common Mistakes
- Leaving the source as a plain range. New rows outside the original range are invisible to the pivot even after a refresh. Convert to a Table first.
- Saving as .xlsx. Macros are stripped on save, so the Change event disappears and the pivot stops updating. Always save as .xlsm.
- Putting the macro on the wrong sheet. A Worksheet_Change event only fires for edits on its own sheet. If the source data lives on a different sheet from the code, nothing happens.
- Expecting a pivot to refresh when a cell changes because of a formula. Worksheet_Change does not fire for formula recalculations. If your source cells are formula-driven, use the Workbook_Open event or a manual refresh instead.
- Forgetting background refresh. With background refresh on, the pivot can return stale results while the macro finishes, which looks like the refresh failed.
- Refreshing a pivot connected to an external data source without credentials. The refresh may prompt for a password or fail silently. Check the connection settings under Data > Queries & Connections.
Tips
- Name your pivot tables (PivotTable Analyze > PivotTable Name) so the macro targets the right one and the code stays readable.
- Use ThisWorkbook.RefreshAll only when every pivot and query should update; it also refreshes Power Query connections, which can be slow on large models.
- If the workbook is shared, test the macro on a copy first. Shared workbooks have limited macro support and some events do not fire.
- For pivots fed by Power Query, set the query to refresh on open under Data > Queries & Connections > Properties, then refresh the pivot after the query loads.
- Keep a manual refresh habit for critical reports: automatic refresh is convenient, but a quick Alt+F5 before sharing confirms the numbers are current.
Troubleshooting
The pivot does not update when I edit the source. Check that the workbook is saved as .xlsm, macros are enabled, and the code sits on the sheet where you are typing. If the source cells contain formulas, the Change event will not fire; switch to the open-refresh method or refresh manually.
I get a macro security warning every time. This is normal for macro-enabled files from outside your Trusted Locations. Move the file to a trusted folder or ask your administrator about macro policy. Do not disable security settings globally.
The refresh is very slow. Turn off background refresh, reduce the source range to a Table rather than whole columns, and avoid RefreshAll if only one pivot needs updating. Large data models with many relationships take longer by design.
The pivot shows old categories after new data is added. A refresh updates values, but a new item in a field may need the pivot's field list to be re-read. Right-click the pivot and choose Refresh; if the item still does not appear, check that the new row is inside the Table and that the field is in the Rows or Columns area.
The file opens with a "macros have been disabled" bar and the pivot is stale. Click Enable Content, or add the folder to Trusted Locations via File > Options > Trust Center > Trust Center Settings > Trusted Locations. Only do this for folders you control.
Frequently Asked Questions
Can Excel refresh a pivot table automatically without VBA?
Not on every edit. The built-in option only refreshes when the file opens (PivotTable Options > Data > Refresh data when opening the file). For refresh-on-change you need a short macro.
Does the refresh-on-open setting work in Excel for the web?
Excel for the web has limited support for macros and some pivot options. The setting may not carry over reliably; use the desktop app for automatic refresh.
Will automatic refresh update a pivot connected to Power Query?
Only if the query itself refreshes. Set the query to refresh on open in Queries & Connections > Properties, and the pivot will pick up the new data after the query loads.
Why does my macro refresh all pivots instead of one?
RefreshAll refreshes every pivot and query in the workbook. To target one pivot, use its name with PivotCache.Refresh, for example PivotTables("PivotTable1").PivotCache.Refresh.
Is automatic refresh safe for shared workbooks?
Shared workbooks have limited macro and event support, so refresh-on-change may not fire. Test on a copy and consider having one person own the refresh.
What shortcut refreshes a pivot table manually?
Alt+F5 in Excel for Windows refreshes the selected pivot. On Mac, use the Refresh button on the PivotTable Analyze tab or right-click the pivot and choose Refresh.