Sub topic 5
Giving the Table a Meaningful Name
This chapter assumes you can create a table from a range with Ctrl+T, you know A1-style references, and you have written basic formulas such as SUM. Here you will learn why a table name matters, how to rename a table, what the naming rules are, and what goes wrong when names are careless.
Why the name matters
When you create a table, Excel gives it a default name such as Table1, Table2 and so on. The name is not decoration. It is the identifier that formulas, PivotTables, Power Query, charts and VBA code use to refer to the whole table.
A structured reference such as SalesTable[Amount] points at the Amount column of the table called SalesTable. The reference stays correct when rows are added or removed, because Excel resolves the name to the table's current extent each time. Compare these two formulas:
=SUM(Table1[Amount])
=SUM(SalesTable[Amount])Both work. Only the second tells a reader what is being summed. In a workbook with five tables named Table1 to Table5, the first form forces every reader to open each table to find out what it contains.
A good name has these effects:
- Formulas become self-documenting.
- The Name Box and the Go To dialog list tables by name, so you can jump to them.
- Tools that ask you to pick a data source (PivotTable, Power Query, data validation lists) show readable choices.
- VBA code that uses
ListObjects("SalesTable")keeps working if the table moves to another position on the sheet.
How to rename a table
There are three ways to change a table name.
From the Ribbon
- Click any cell inside the table.
- Open the Table Design tab. In some versions this tab is called Table Tools > Design.
- In the Properties group, edit the Table Name box.
- Press Enter. The name is not applied until you do.
From the Name Manager
- Press Ctrl+F3 to open the Name Manager.
- Select the table in the list. Tables appear alongside defined names, with a table icon.
- Click Edit, type the new name and confirm.
The Name Manager is useful for reviewing every table name in a workbook at once.
From VBA
The Name property of a ListObject can be set directly:
Sub RenameFirstTable()
ActiveSheet.ListObjects(1).Name = "SalesTable"
End SubIf the name is invalid or already in use, VBA raises a run-time error instead of fixing the name for you.
Naming rules
Table names follow the same rules as defined names in Excel.
| Rule | Valid example | Invalid example |
|---|---|---|
| Starts with a letter, underscore or backslash | `SalesTable`, `_Archive` | `2024Sales` |
| Contains no spaces | `Sales_2024` | `Sales 2024` |
| Is not a cell reference | `Orders_Q1` | `Q1`, `R1C1`, `TAX2024` |
| Is unique in the workbook, ignoring case | `SalesTable` | `salestable` when `SalesTable` exists |
| Is at most 255 characters | `Customers` | A 300-character string |
| Is not a single letter C, c, R or r | `Rates` | `R` |
Two of these rules cause most of the trouble. The first is the cell-reference rule. A name like TAX2024 looks like a name, but column TAX and row 2024 form a valid cell address in current Excel, so the name is rejected. The second is uniqueness. A table name cannot match any defined name, and it cannot match another table, even one on a different worksheet.
Naming conventions
Excel does not enforce a style, but a consistent one saves time. Common choices:
- PascalCase, such as
SalesTableorCustomerOrders. Easy to type because no underscore key is needed. - A prefix, such as
tbl_SalesortblSales. This separates tables from other names in formulas and in VBA, at the cost of a few more characters. - Singular or plural. Pick one. Many people use plural for tables of records, such as
Orders, because the table holds many of them.
Avoid names that describe the layout, like Sheet2Data, or the date, like Jan, because both go stale quickly.
What happens to formulas when you rename
Renaming is safe for formulas that already use the table. Suppose a cell contains =SUM(Table1[Amount]). When you change the name to SalesTable, Excel rewrites the formula to =SUM(SalesTable[Amount]) automatically. The same rewrite applies to:
- Structured references on every sheet in the workbook.
- Defined names whose Refers To box uses the table.
- Conditional formatting rules and data validation that refer to the table.
- Chart series and PivotTable sources based on the table.
Two things are not rewritten:
- Text strings. A formula such as
=INDIRECT("Table1[Amount]")keeps the old name inside the quotation marks and breaks after the rename. - VBA code. A macro with
ListObjects("Table1")fails with "Subscript out of range" once the table is renamed. Search your modules for the old name.
Formulas in other workbooks that link to this table by name are also affected. External references to a table are stored as text until the source workbook is open, so rename a shared table only after checking who links to it.
A worked example
Start with a table of orders. The table has the default name Table1 and the columns Date, Region, Quantity, Unit Price and Amount. On another sheet, cell B2 holds this formula:
=SUMIFS(Table1[Amount],Table1[Region],"West")Rename the table to Orders:
- Click a cell in the table.
- On the Table Design tab, replace
Table1in the Table Name box withOrders. - Press Enter.
Cell B2 now shows:
=SUMIFS(Orders[Amount],Orders[Region],"West")The result is unchanged, and the formula now reads as a sentence: sum the Amount of Orders where Region is West.
Now check the name from the Name Box. Click the arrow on the Name Box at the left of the formula bar. The list shows Orders. Selecting it selects the table's data body, not the header row or the total row. This is a quick way to confirm the table's current extent.
Tables and defined names share one namespace
A table name lives in the same list as defined names, such as ranges named through the Name Box. That has three consequences.
- You cannot create a defined name
Ordersif a table is already calledOrders. - If you try to rename a table to a name that a defined name already uses, Excel shows an error and keeps the old name.
- Sheet-scoped names can hide the problem. A name limited to one sheet does not block a table name, but it can make formulas on that sheet ambiguous. Avoid reusing the same text.
If a rename fails and you cannot see why, open the Name Manager and sort by Name. A leftover defined name from a deleted range is a frequent cause.
Checking and listing table names
To see every table in the workbook with its sheet and range, the following macro writes a list to the Immediate window:
Sub ListAllTables()
Dim ws As Worksheet
Dim tbl As ListObject
For Each ws In ThisWorkbook.Worksheets
For Each tbl In ws.ListObjects
Debug.Print ws.Name & " | " & tbl.Name & " | " & tbl.Range.Address
Next tbl
Next ws
End SubPress Ctrl+G in the VBA editor to open the Immediate window. Each line shows the sheet, the table name and the range that the table occupies, header row included.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
| The name reverts to the old one after you press Enter | The name breaks a rule, or it is already in use | Remove spaces, avoid cell-like names, and check the Name Manager for duplicates |
| A message says the name is not valid | Starts with a digit, or contains a space or symbol other than underscore, period or backslash | Rename using letters, digits and underscores |
| A formula shows `#REF!` after a rename | The formula used the name in a text string, or a linked workbook was closed | Edit the string to use the new name, or open the source workbook |
| A macro fails with "Subscript out of range" | The VBA code still names the old table | Update the string, or refer to the table by index or by a variable |
| Two tables seem to have the same name | One name differs only by case, such as `Sales` and `SALES` | Names are case-insensitive, so give each table a distinct word |
Practical guidance
- Rename a table straight after you create it, before you write formulas. The rewrite is automatic either way, but a habit of naming first keeps your work readable while you build it.
- Name the table for its content, not its appearance or location.
- Keep names short enough to type. Excel's formula autocomplete lists table names as you type, so a clear prefix of a few letters is enough to select one.
- Write the name into your documentation or a cover sheet if others will use the workbook.
Where this fits
The table name is the first half of every structured reference. The header names supply the second half, which is why the next chapters on structured references and calculated columns rely on the name you set here.
Exercise
A colleague tries to name a table Q3 and then 2024 Sales. Both are rejected. Explain why, and suggest a valid name for a table of third-quarter 2024 sales.
Show answer
Q3 is rejected because it is a valid cell address (column Q, row 3), and names may not look like cell references. 2024 Sales is rejected because it starts with a digit and contains a space. A valid name is Sales_2024_Q3 or Sales2024Q3. Both start with a letter, contain no spaces, and do not resemble a cell address.
Exercise
A workbook has a table renamed from Table1 to Orders. One formula, =SUM(INDIRECT("Table1[Amount]")), now returns #REF!, and a macro using ListObjects("Table1") stops with a run-time error. Why did Excel fix other formulas but not these, and how would you repair both?
Show answer
Excel rewrites real references when a table is renamed, but the text inside quotation marks is only a string, and a VBA string is not part of the workbook's reference graph. Change the formula to =SUM(INDIRECT("Orders[Amount]")), or better, replace it with =SUM(Orders[Amount]). In the macro, change the string to ListObjects("Orders"), or use ListObjects(1) or a variable that holds the table.