Sub topic 14
Charts that grow with your data using Tables
This chapter assumes you can select ranges, insert a column or line chart, and open the Select Data dialog. You should also know what a series and a category are. Here you will learn how an Excel Table keeps a chart current as rows are added or removed, and where this approach breaks.
The problem: fixed ranges
When you insert a chart from a plain range, each series stores a fixed reference such as =Sheet1!$B$2:$B$5. If you type a new row under row 5, the chart ignores it. You then have to open Select Data and extend the range by hand. On a sheet that is updated weekly, this step is easy to forget, and the chart quietly shows stale numbers.
An Excel Table fixes this. A Table is a named, structured block of cells that expands automatically when you add data next to it or beneath it. A chart built on a Table reads the Table's columns, so the chart range expands with them.
Convert a range to a Table
Use this layout from earlier in the tutorial:
Region Sales
North 120
South 95
East 140
West 80To convert it:
- Click any cell in the data.
- Press Ctrl+T, or choose Insert > Table.
- Confirm the range and keep "My table has headers" ticked.
- Click OK.
Excel applies banded formatting and shows a Table Design tab on the ribbon. On that tab, the Table Name box at the left holds a default name like Table1. Rename it to something meaningful, such as SalesByRegion. You will need this name if you later use formulas or VBA.
Build the chart from the Table
Click inside the Table and choose Insert > Column or Bar Chart > Clustered Column. Excel treats the header row as series names and the first text column as categories, just as it does for a plain range.
Now test the link:
- Type
Centralin the cell directly belowWest. - Type
110in the cell to its right. - Watch the Table grow to include the new row, and the chart add a fifth column.
You did not touch Select Data. The chart's series formula still points at cells, but Excel rewrites those references whenever the Table's size changes.
How the link works
Click a column in the chart and look at the formula bar. You will see something like:
=SERIES(Sheet1!$B$1,Sheet1!$A$2:$A$6,Sheet1!$B$2:$B$6,1)The four arguments are the series name, the category range, the value range, and the plot order. Excel shows ordinary cell references, not Table names, even when the chart is tied to a Table. Behind the scenes it tracks that those ranges coincide with Table columns, and it resizes them when the Table resizes.
This tracking is why the technique has limits. It works as long as the series range covers a whole Table column. If you edit a series by hand and type a range that covers only part of a column, the link is lost for that series.
flowchart TDThe diagram below shows the chain of events.
What expands and what does not
A Table-linked chart responds to several actions. Others need your attention.
| Action | Effect on the chart |
|---|---|
| Type a row directly below the Table | Chart adds a point |
| Paste data below the Table | Table expands, chart adds points |
| Insert a row inside the Table | Chart adds a point in that position |
| Delete a Table row | Chart removes that point |
| Add a new column next to the Table | Table expands, but the chart does not add a series |
| Leave a blank row, then type below it | Table does not expand, chart unchanged |
| Filter the Table | Hidden rows disappear from the chart |
The new-column case is a common surprise. The chart's series list is fixed, and Excel does not add a series on its own. Open Select Data and add the new column as a series. Because that column is already part of the Table, the new series will also stay in sync from then on.
Filtering and hidden rows
By default, a chart does not plot data in hidden rows or columns. Filtering a Table hides rows, so the chart shows only the visible ones. This is useful: a slicer or filter on the Table becomes a quick way to change what the chart displays.
If you want hidden rows to stay in the chart, select the chart, choose Chart Design > Select Data, click Hidden and Empty Cells, and tick "Show data in hidden rows and columns". Be careful with this setting. It makes the chart disagree with what the viewer sees in the Table.
Sorting a Table
Sorting a Table changes the order of the categories in the chart, because the chart reads the rows in sheet order. This works in your favor. To get a ranked bar chart, sort the Table by Sales from largest to smallest. For a bar chart, the first row appears at the bottom of the axis. Turn on "Categories in reverse order" under Format Axis if you want the largest value at the top.
Tables and the VBA macro
The macro in the earlier chapter used a fixed range, A1:B5. A chart made that way has a fixed range, even if the data is a Table. To tie VBA charts to a Table, pass the Table's range, as in this version:
Sub CreateTableChart()
Dim lo As ListObject
Dim co As ChartObject
Set lo = ActiveSheet.ListObjects("SalesByRegion")
Set co = ActiveSheet.ChartObjects.Add(Left:=100, Top:=50, Width:=400, Height:=250)
With co.Chart
.SetSourceData Source:=lo.Range
.ChartType = xlColumnClustered
.HasTitle = True
.ChartTitle.Text = "Sales by Region"
End With
End Sublo.Range covers the header row and all data rows. Because the source is the whole Table, the chart expands with it. Use lo.DataBodyRange only when you do not want the header row used as series names. The code assumes the Table was renamed to SalesByRegion. If the name differs, Excel raises a "subscript out of range" error.
Common errors
- Chart does not grow. The chart was created before the Table, or a series was hand-edited to a partial range. Rebuild the chart from inside the Table.
- A total row appears as a data point. If you turn on the Table's Total Row, it sits in the Table range, and some charts may plot it. Keep totals outside the Table, or exclude the row in Select Data.
- Blank rows break expansion. A Table only grows when you type in the row immediately below it. Remove the gap.
- Pie chart shows too many slices. Tables make it easy to add rows without thinking. A pie chart with ten tiny slices is hard to read. Revisit whether a bar chart suits the data better.
- Axis scale jumps. When a new value is much larger than the others, Excel rescales the axis automatically. If a fixed scale matters, set the axis bounds yourself under Format Axis.
Limits of this technique
Tables handle growth in rows well. They do not give you a "show only the last 12 months" window. For a rolling window you need dynamic named ranges with formulas such as OFFSET or INDEX, which are a separate technique. For most reports, a Table plus a filter is simpler and less error-prone.
Exercise
You built a column chart from a plain range, then converted the range to a Table, and typed a new row below it. The Table grew but the chart did not. What are two ways to fix it, and which is more reliable?
Show answer
You can either edit each series in Select Data so its range covers the full Table column, or delete the chart and insert a new one while a cell inside the Table is selected. Rebuilding the chart from inside the Table is more reliable, because Excel then links the series to the Table columns from the start.
Exercise
A Table has columns Month, Revenue, and Costs. The chart plots only Revenue. You add a new column called Profit beside Costs. Does the chart show Profit? What do you do?
Show answer
No. The Table expands to include Profit, but the chart's series list does not change. Open Select Data, click Add under Legend Entries (Series), and choose the Profit header as the name and the Profit data cells as the values. From then on, new rows will extend the Profit series too.