Sub topic 1
What a Table Adds to a Plain Range
Prerequisites
This chapter assumes you can do the following:
- Select cells and enter data and formulas.
- Find commands on the Ribbon and use common keyboard shortcuts.
- Read A1-style references such as
B2andB2:B20.
You do not need VBA knowledge. A short VBA example near the end is optional.
The core idea
A plain range is a block of cells. Excel treats each cell on its own, and you keep track of where the data starts and ends. An Excel table (stored internally as a ListObject) is a named object that wraps a block of cells. It knows its own header row, its own columns and its own size. Because it has that knowledge, Excel can do things for you that it cannot do reliably for a bare range.
The data is the same in both cases. You can look at the grid and see rows and columns either way. The difference is that the table is an object with a name, and formulas, charts, PivotTables and macros can refer to it by that name.
The rest of this tutorial turns a range into a table and uses what that gives you. This chapter explains what changes, so the later steps make sense.
A side-by-side comparison
| Capability | Plain range | Excel table |
|---|---|---|
| Has a name | Only if you define one | Gets a default name such as Table1, and you can rename it |
| Grows with new data | No. You extend references yourself | Yes. Typing below the last row adds a row |
| Formulas refer to columns | By cell addresses, such as `C2:C100` | By names, such as `SalesTable[Amount]` |
| Formula fill-down | Manual copy or fill | Calculated columns fill automatically |
| Sort and filter | Only after you turn on AutoFilter | Header buttons appear automatically |
| Banded rows and header formatting | Applied by hand | Applied by a table style |
| Total row | You write the formula yourself | Built-in row with a function list |
| Slicers | Not available | Available |
Feature 1: a name and a defined extent
When you create a table, Excel gives it a default name (Table1, Table2 and so on). You will normally rename it to something meaningful, for example SalesTable. A later chapter covers naming rules.
The name matters because the table's extent is stored with it. Excel always knows which cells belong to the table, so a formula never needs a hard-coded address.
Compare two ways of summing a column. With a plain range:
=SUM(C2:C100)This formula covers only rows 2 to 100. If you add data in row 101, the sum misses it unless you edit the formula or Excel happens to extend the reference.
With a table:
=SUM(SalesTable[Amount])This formula sums the Amount column of the table named SalesTable. The result includes new rows automatically as the table grows.
Feature 2: automatic expansion
If you type in the row directly below a table, or paste data there, the table grows to include the new row. The formatting, formulas and filter settings carry over. Anything that refers to the table by name sees the larger table immediately. That includes formulas, charts and PivotTables that use the table as their source.
Expansion can also be less welcome. If cells below the table contain other data, a table cannot grow into them, and Excel stops you or shows a warning. Keep the area directly below a table empty.
Feature 3: structured references
A structured reference is a formula reference that uses the table name and column headers instead of cell addresses. The pattern looks like this:
SalesTable[Amount]means the whole data part of the Amount column.SalesTable[[#Headers],[Amount]]means the header cell of that column.[@Amount]means the Amount value in the current row, when the formula is inside the table.
Structured references are easier to read than addresses. =SUM(SalesTable[Amount]) says what it does. =SUM(C2:C100) does not. They also follow the table. If you rename a column header, Excel updates formulas that use it. If you insert or delete a row, the reference still points to the right data.
A column name that contains spaces or special characters needs an extra pair of brackets, as in [@[Unit Price]]. Later chapters cover the full syntax.
Feature 4: calculated columns
When you enter a formula in a table column, Excel can fill the same formula into every row of that column. This is a calculated column. Suppose the table has columns named Quantity and Unit Price, and you type this in a new column:
=[@Quantity]*[@[Unit Price]]Excel multiplies the two columns for the current row and fills the formula down the whole column. When you add a row later, the formula is filled in for it as well. You do not need to copy it down.
This removes a common spreadsheet error. In a plain range, someone can paste a value over a formula in row 57 and nobody notices. A calculated column makes inconsistent cells easier to spot, because Excel flags a cell that differs from the rest of the column.
Feature 5: sorting and filtering
A table shows a drop-down button on each header cell. From it you can sort ascending or descending, filter by values, text or color, and clear a filter. With a plain range you must first turn on AutoFilter, and Excel has to guess where the data ends.
A table does not guess, because it already has a defined extent. Sorting a table column therefore moves whole rows together, and the rows do not lose their alignment. Filtering hides entire rows of the table and leaves cells outside the table alone.
Slicers build on filtering. A slicer is a set of buttons that filters a table by one column, which is useful for dashboards and for people who prefer clicking to opening a drop-down. Slicers work with tables and PivotTables, and a later chapter covers them.
Feature 6: the total row
A table can show a total row at the bottom. You switch it on from Table Design > Total Row. Each cell in that row has a drop-down list of functions, such as Sum, Average and Count.
The total row uses SUBTOTAL, not SUM. For example:
=SUBTOTAL(109,SalesTable[Amount])The function number 109 means "sum, ignoring rows hidden by a filter". The total therefore changes when you filter the table, which a plain SUM would not do. This is a reason to prefer the built-in total row over a hand-written total underneath the data.
Feature 7: styles
A table style supplies the header formatting and the banded (alternating) rows. Because the style belongs to the table, it stays with the data when the table grows. New rows get the same banding. If you sort or filter, the banding is recalculated, so the stripes stay even. With manual formatting on a plain range, banding breaks as soon as you sort.
You can switch the header row, total row, banded rows, first column and last column on or off. These are style options, and they change only the look of the table.
How the pieces fit together
The diagram shows why the order of this tutorial matters. The name and the header row come first, because structured references are built from them. Calculated columns depend on both structured references and expansion.
What a table does not do
Tables are not a replacement for everything.
- A table must have a single header row, and each header must be unique and non-empty. Merged cells in the data area are not allowed.
- A table cannot hold multi-row headers or subtotal rows in the middle of the data.
- A table is one rectangular block. If your layout has several blocks, you need one table for each.
- Some features are limited in a table. For example, array formulas that span several cells in a table are not allowed, and a table cannot be shared in a legacy shared workbook.
- Tables add a little overhead. For a few hundred rows you will not notice. For very large data sets, a PivotTable or Power Query may be a better tool.
You can always go back. A table can be converted to a plain range, and the data and formatting stay. The conversion is covered in a later chapter.
A first look at automation
Everything above can be done from the Ribbon. Tables are also available to VBA as ListObject objects. This macro turns the block of data around A1 into a table and names it:
Sub CreateSalesTable()
Dim ws As Worksheet
Dim tbl As ListObject
Set ws = ActiveSheet
Set tbl = ws.ListObjects.Add(xlSrcRange, ws.Range("A1").CurrentRegion, , xlYes)
tbl.Name = "SalesTable"
tbl.TableStyle = "TableStyleMedium2"
tbl.ShowTotals = True
End SubThe xlYes argument tells Excel that the first row holds headers. CurrentRegion selects the contiguous block of data around A1, which is the same block Excel selects when you press Ctrl+T with one cell active. Treat this as a preview. A final chapter covers ListObjects in more detail.
Common mistakes at this stage
- Treating a table as only formatting. The stripes are a style. The real change is the object, its name and its extent.
- Leaving the default name.
Table1works, but formulas become harder to read. Rename tables early, before you write formulas that use them. - Placing data directly under the table. This blocks expansion. Leave the rows below empty.
- Expecting a plain
SUMtotal to respond to filters. Use the total row, or writeSUBTOTAL(109, ...)yourself. - Converting data with blank or duplicate headers. Excel fills in default headers such as Column1, which you then need to fix.
Exercise
A worksheet has sales data in A1:D200 as a plain range. A colleague writes =SUM(D2:D200) under it and later adds 30 new rows below row 200. If the data had been a table named SalesTable, which formula would keep the total correct, and why?
Show answer
=SUM(SalesTable[Amount]), where Amount stands for the header of the column that was column D. The reference points to the table's column, not to fixed cell addresses. The table grows when rows are added below it, so the column reference includes the new rows with no edit to the formula.
Exercise
You filter a table so that only the rows for one region are visible. A cell below the table contains =SUM(SalesTable[Amount]) and the table's total row shows =SUBTOTAL(109,SalesTable[Amount]). Which of the two values changes, and why?
Show answer
Only the total row value changes. SUBTOTAL with function number 109 ignores rows hidden by a filter, so it totals the visible rows. SUM adds every row in the column, whether the row is visible or hidden, so its result stays the same.