Sub topic 12
Refreshing and changing the data source
This chapter assumes you can already create a PivotTable from a range or an Excel Table, and that you know the four areas of the PivotTable Fields pane. It covers why a PivotTable goes out of date, how to bring it up to date, and how to point it at a different source.
Why a PivotTable does not update by itself
A PivotTable does not read your worksheet cells live. When you create one, Excel copies the source data into a hidden store called the pivot cache. The PivotTable draws its numbers from that cache, not from the cells.
This design makes pivots fast, but it has a consequence. If you edit a value, add a row, or delete a record in the source, the PivotTable keeps showing the old numbers until you refresh it. Refreshing rebuilds the cache from the source and redraws the report.
The most common "bug" report about PivotTables is a stale result. The data is correct, and the PivotTable has not been told to reread it.
Refreshing manually
Click any cell inside the PivotTable, then use one of these methods:
- On the PivotTable Analyze tab, choose Refresh to update the selected PivotTable.
- Choose Refresh All (from the Refresh drop-down, or on the Data tab) to update every PivotTable and data connection in the workbook.
- Right-click a cell in the PivotTable and choose Refresh.
- Press Alt+F5 to refresh the selected PivotTable, or Ctrl+Alt+F5 to refresh everything.
PivotTables that share one pivot cache are refreshed together. Excel shares a cache when you create a second PivotTable from the same source range, so refreshing one of them also updates the others.
Refreshing automatically
You can ask Excel to refresh without a manual step.
- Click inside the PivotTable.
- On the PivotTable Analyze tab, choose Options.
- Open the Data tab of the dialog.
- Tick Refresh data when opening the file.
With this option on, the PivotTable rereads its source each time the workbook opens. It does not refresh when a source cell changes while the workbook is open. For that you need a macro. This one refreshes every PivotTable and data connection:
Sub RefreshAllPivots()
ThisWorkbook.RefreshAll
End SubYou can assign it to a button, or call it from a worksheet event. Save the workbook as .xlsm if it contains macros.
The source range problem
Refreshing only rereads the range the PivotTable already points to. If that range is fixed, new rows fall outside it.
Suppose your source is A1:E6, five records under a header row:
Date,Region,Product,Units,Sales
2025-01-05,East,Widget,10,250
2025-01-12,West,Gadget,4,180
2025-02-03,East,Gadget,7,315
2025-02-14,West,Widget,12,300
2025-03-09,East,Widget,5,125If you type a sixth record in row 7 and click Refresh, nothing changes. The PivotTable still points to A1:E6, so row 7 is never read. The refresh worked correctly. The source definition was too small.
There are two ways to fix this: use an Excel Table, or change the source by hand.
Use an Excel Table as the source
An Excel Table grows automatically when you type directly beneath it, and a PivotTable built on the table refers to the table by name, not to a fixed address. After you add rows, a refresh picks them up.
To convert the range, click a cell in the data and press Ctrl+T, confirm that My table has headers is ticked, and give the table a clear name on the Table Design tab, such as tblSales.
This is the recommended approach. It needs no further maintenance, and the PivotTable keeps working as the data grows.
If you already built the PivotTable on a plain range, you can convert the range to a table afterwards and then point the PivotTable at the table name, as described next.
Change the data source manually
- Click inside the PivotTable.
- On the PivotTable Analyze tab, choose Change Data Source, then Change Data Source again.
- In the Table/Range box, type the new reference, for example
tblSalesorSheet1!$A$1:$E$20. - Click OK.
Excel rebuilds the cache from the new source and refreshes the report. This is also how you point a PivotTable at an entirely different dataset, such as a new year's data with the same columns.
What happens to your layout when the source changes
Excel keeps your field layout across a refresh when the field names still exist. Problems appear when the source columns change.
| Change in the source | Effect on the PivotTable after refresh |
|---|---|
| New rows added inside the source range | New records included in totals |
| New rows below a fixed range | Ignored until the source is extended |
| Column header renamed | The old field disappears from the layout. The renamed column appears as a new, unplaced field |
| Column deleted | The field is removed from the layout. Formulas that use it, such as calculated fields, may fail |
| New column added at the edge of the source | Appears in the field list only if the source range includes it |
| New category value (for example a new region) | Appears as a new row or column item |
The renamed-header case catches many people. Pivot fields are matched by header text, so changing Sales to Revenue breaks the link. Put the renamed field back into the Values area and reapply any formatting.
Old items that stay in drop-downs
After you delete records, a category can remain in a filter or slicer list even though no data uses it. For example, if every East record is removed, East may still be listed. Excel keeps old items in the cache by default.
To clear them:
- Click inside the PivotTable and choose Options on the PivotTable Analyze tab.
- Open the Data tab.
- Set Number of items to retain per field to None.
- Click OK and refresh.
Formatting that disappears on refresh
Refreshing can change column widths and reset cell formatting. Two options on the Layout & Format tab of the PivotTable Options dialog control this:
- Autofit column widths on update: untick it to keep widths you set.
- Preserve cell formatting on update: tick it to keep number and style formatting.
Applying number formats through Value Field Settings is more reliable than formatting cells directly, because the format is stored with the field.
Refresh failures
A refresh can fail or give odd results. The usual causes are:
- The source moved or was renamed. If the source sheet or table was deleted or renamed, Excel reports a reference error. Use Change Data Source to repair it.
- The source is in a closed external workbook. Open the source file, or update the link under Data > Queries & Connections.
- The PivotTable would overlap another PivotTable or data. Refresh can grow a PivotTable beyond its old footprint. Excel stops with a message about overlapping. Move one of the reports, or leave empty space below and to the right of each.
- Filtered or hidden source rows. Hiding rows in the source does not remove them from the PivotTable. Only deleting rows, or filtering inside the PivotTable, does.
A worked example
You have a PivotTable with Region in Rows, Product in Columns, and Sum of Sales in Values, built from the five records above.
- Convert the data to a table named
tblSaleswith Ctrl+T. - Click Change Data Source and enter
tblSales. - Type a new record directly below the table:
2025-03-20,West,Gadget,6,270. The table expands to include it. - Click inside the PivotTable and press Alt+F5.
The West and Gadget cell changes from 180 to 450. Without step 2, the new row would have been ignored.
Exercise
You added 30 new rows below a PivotTable's source range, which is a plain range and not a Table. You click Refresh, but the totals do not change. Why, and what are two ways to fix it?
Show answer
Refresh rereads only the range stored in the PivotTable's definition, and that range ends above the new rows. Fix it by converting the range to an Excel Table, then using Change Data Source to point the PivotTable at the table name so future rows are included automatically. Alternatively, use Change Data Source and enter a larger fixed range that includes the new rows, which must be repeated whenever the data grows.
Exercise
A colleague renames the header Sales to Revenue in the source and refreshes. The Values area is now empty. What happened, and what do you do?
Show answer
Pivot fields are matched by header text, so the old Sales field no longer exists and was removed from the layout. Revenue is a new field. Drag Revenue into the Values area and reapply the number format.