Sub topic 7
How tables grow with your data
This chapter assumes you can already create a table, name it, and read a basic structured reference such as SalesTable[Amount]. It covers what Excel does when you add rows or columns, which other objects follow the growth, and what stops it.
What auto expansion is
A table has defined edges. When you add data touching those edges, Excel can move the edges for you. This is automatic expansion, or auto expansion. A plain range never does this. If you type below A1:D20, you have only put values in cells that happen to be next to the range.
Expansion matters because everything attached to the table by name moves with it. Formulas that use SalesTable[Amount], a chart built on the table, and the formatting and filter buttons all follow the new edges. You do not edit any formula.
Ways a table grows
Excel expands a table in several ways. The first two are automatic. The others are things you do on purpose.
| Action | Result |
|---|---|
| Type or paste in the row directly below the last data row | The table adds a row |
| Type or paste in the column directly right of the last column | The table adds a column |
| Press Tab in the last cell of the last data row | A new empty row is added |
| Drag the resize handle at the bottom-right corner | The table covers the cells you drag over |
| Table Design > Resize Table | You pick a new range in a dialog |
| Right-click > Insert > Table Rows Above (or Columns to the Left) | A row or column is inserted inside the table |
Typing below or beside the table
Suppose SalesTable occupies A1:D20, with headers in row 1. Click A21 and type a value. When you press Enter, the table border jumps to row 21, banding and formatting continue, and any calculated column fills in its formula for the new row.
The same applies to a new column. Type a header in E1, and the table gains a fifth column. Excel picks a name for it only if you leave the header empty. In that case it uses Column1, Column2, and so on. Rename it right away, because structured references use the header text.
Tab in the last cell
The most reliable way to add one row is the keyboard. Select the last cell of the last data row and press Tab. Excel adds a row and puts the cursor in its first cell. You can then fill the row with Tab, which keeps your hands on the keyboard.
Pasting
Pasting follows the same rule as typing. If you paste a block that starts in the row directly below the table, the table grows to include all the pasted rows. If the pasted block is wider than the table, it grows to the right only when the block starts directly below the table and the extra columns are adjacent to its right edge. Check the result after a wide paste. The border can end up somewhere you did not expect.
The setting behind it
Expansion by typing is controlled by an AutoCorrect option. Open File > Options > Proofing > AutoCorrect Options > AutoFormat As You Type. The option is "Include new rows and columns in table". It is on by default.
If expansion happens when you do not want it, you have two choices.
- Press Ctrl+Z immediately after the table grows. The change is undone, but the cell value stays. You can also click the Auto Expansion Options smart tag, a small icon that appears near the new row, and choose "Undo Table AutoExpansion".
- Turn the option off in AutoCorrect Options. This affects every workbook in your Excel installation, not only the current one.
Turning it off is a poor default for shared work. Other people who open the file will not have the same setting, so the table behaves differently on their machines.
What follows the table
When the table grows, these objects update without further action:
- Formulas that use structured references, for example
=SUM(SalesTable[Amount]). - Calculated columns, which fill the new row.
- Charts whose series point at table columns.
- Data validation lists, conditional formatting and number formats applied to a whole column of the table.
- Filter and sort ranges.
A few things do not update by themselves:
- A PivotTable based on the table still needs Refresh, or Data > Refresh All. It will then see the new rows, because its source is the table name.
- Formulas that use ordinary references, such as
=SUM(D2:D20), are not rewritten. Excel sometimes extends a plain range reference if it covers the entire table column, but you should not depend on it. Use a structured reference. - Named ranges that point at a fixed address, such as
$D$2:$D$20, stay fixed.
The next formula grows with the table. Compare it with the fixed-address version above.
=SUM(SalesTable[Amount])After you add a row, this formula covers it. A formula written as =SUM(D2:D20) still stops at row 20, or may be extended by Excel inconsistently.
Sequence of events when you type below the table
When expansion does not happen
If a table does not grow, one of these is usually the cause.
- A gap. You typed in row 22 when the table ends at row 20. Row 21 is empty, so the cell is not adjacent. Move the value to row 21, or resize the table.
- The total row is visible. With a total row shown, the row beneath the data is the total row itself. Typing under the total row does not expand the table. Add rows with Insert > Table Rows Above on a data row, or with the resize handle. Alternatively, turn the total row off, add data, and turn it back on.
- The option is off. Check the AutoCorrect setting described above.
- The sheet is protected. Excel cannot add rows or columns to a table on a protected sheet, even if the cells are unlocked.
- Something blocks the way. Inserting a row with Tab or the Insert command shifts cells below the table down. If another object, such as a second table, sits directly below in the same columns, Excel can refuse and show a message that the operation would move cells in a table. Leave at least one empty row between stacked tables, or place them side by side with an empty column between them.
- Typing happened off the edge, not adjacent. For columns, the same gap rule applies on the right.
A table also cannot expand across another table. Two tables placed next to each other with no empty column between them cannot grow sideways.
Resizing on purpose
Sometimes you want to change the extent of a table directly. You can drag the handle in the bottom-right corner, or use Table Design > Resize Table and enter a new range. Two rules apply. The header row must remain in the same row, and the new range must include the existing header cells. You cannot move a table by resizing.
Shrinking a table does not delete the data left outside it. The cells remain on the sheet as ordinary values, without table formatting. Calculated column formulas in those rows stay as normal formulas too.
Growing a table with VBA
When a macro adds data, it is safer to use the table's own methods than to write to cells below the table and hope that expansion happens. Writing from VBA does not always trigger the AutoCorrect behavior that typing does.
Sub AddSaleRow()
Dim tbl As ListObject
Dim newRow As ListRow
Set tbl = ActiveSheet.ListObjects("SalesTable")
Set newRow = tbl.ListRows.Add
newRow.Range.Cells(1, tbl.ListColumns("Quantity").Index).Value = 5
newRow.Range.Cells(1, tbl.ListColumns("Unit Price").Index).Value = 12.5
End SubListRows.Add appends a row at the bottom of the data body. With a total row visible it inserts above the total row, so it works in the case where typing does not. The Amount column is filled by its calculated column formula. The macro addresses columns by header name, so it keeps working if someone reorders the columns.
To change the extent of the table in one step, use Resize.
Sub ExtendSalesTable()
Dim tbl As ListObject
Set tbl = ActiveSheet.ListObjects("SalesTable")
tbl.Resize tbl.Range.Resize(tbl.Range.Rows.Count + 10)
End Subtbl.Range includes the header row and any total row. This macro extends the table by ten rows. The new range still begins at the header cell, so the call is valid. If a total row is visible, remember that tbl.Range includes it, so the new range makes the total row part of the extension. Turn the total row off first if you need exact control.
Practical habits
- Keep the table's neighbors clear. Leave empty cells directly below and to the right, or leave one blank row or column as a buffer.
- Do not store notes or totals directly below a table. They block expansion and look like data to the next person.
- Use structured references for every formula that needs to cover the table's data.
- After a large paste, check the table border and the row count. Select any cell and look at the name box, or press Ctrl+A twice to see what Excel treats as the table.
Exercise
A table named OrdersTable covers A1:E50 and has a total row visible in row 51. You type a new order in row 52, but the table does not grow. Why, and how can you add the order correctly?
Show answer
Row 51 is the total row, which is part of the table. Row 52 is outside the table and not adjacent to the data body, so typing there does not trigger expansion. Add the row by right-clicking a data row and choosing Insert > Table Rows Above, by dragging the resize handle, or by turning off the total row, entering the data in the next row, and turning the total row back on. In VBA, OrdersTable.ListRows.Add inserts above the total row.
Exercise
A workbook has a formula =SUM(D2:D50) over a table column, and a second formula =SUM(OrdersTable[Amount]). You add three rows to the table. Which formula is guaranteed to include them, and which setting can stop the table itself from growing when you type under it?
Show answer
The structured reference =SUM(OrdersTable[Amount]) is guaranteed to include the new rows, because it refers to the column by name. The fixed range D2:D50 is not guaranteed to change. The AutoCorrect option "Include new rows and columns in table" (File > Options > Proofing > AutoCorrect Options > AutoFormat As You Type) controls whether typing below the table expands it.