Sub topic 4
Getting the header row right
This chapter assumes you can select ranges, enter formulas, and press Ctrl+T to create a table. It covers how Excel treats the first row of a table, which is the most common source of surprises in the first minute of using one.
Why the header row matters
In a plain range, the first row is a row like any other. Once the range becomes a table, that row becomes the header row, and Excel uses its cell values as column names. Those names appear in the following places:
- Structured references such as
SalesTable[Amount]and[@Quantity]. - The filter buttons on each column.
- The column letters of the worksheet. When you scroll down inside a table, Excel replaces the A, B, C labels with the table's header names.
- VBA code that reads
ListColumns("Amount").
If a header is wrong, every formula and macro that refers to it inherits the problem. Fixing headers before you build on them is cheaper than fixing them afterwards.
What a valid header looks like
Excel enforces these rules when it creates the table.
- Every header must contain a value. A blank header cell is filled with a placeholder named
Column1,Column2, and so on. - Every header must be unique. If two headers have the same text, Excel appends a number to the later one, so a second
SalesbecomesSales2. - Every header is stored as text. A number such as
2025or a date typed into a header cell becomes text. The value looks the same but it is no longer a number. - A header cannot contain a formula. If the cell had one, Excel keeps the displayed result as plain text.
- A header can be at most 255 characters long.
The placeholder and renaming behavior is helpful, but it also hides problems. A table with Column3 and Sales2 in it was usually built from a range with a missing or repeated header, and a clean source range avoids both.
The "My table has headers" checkbox
When you press Ctrl+T, or choose Insert > Table, Excel shows the Create Table dialog. It contains the range address and a checkbox labeled My table has headers. Excel guesses the checkbox state. It selects it when the first row looks like text and the rows below look different, for example when the first row is text and the rows below hold numbers.
The guess can be wrong. The two ways to get it wrong behave differently.
| Situation | Checkbox state | Result |
|---|---|---|
| Your first row is headers | Cleared by mistake | Excel treats the headers as data and adds a new row of `Column1`, `Column2`, ... above them. Your real headers become the first data row. |
| Your first row is data | Selected by mistake | Excel promotes the first data row to the header row. That row stops being data and its values become column names. |
In both cases, look at the dialog before you press OK. If you already pressed OK, press Ctrl+Z and repeat the step with the right setting.
The flow below shows how the header row is decided during creation.
Worked example: fixing headers on an existing table
Suppose you converted this range, and the first row contained a blank cell and two Sales headers:
| Region | Sales | Sales | (blank) |
|---|---|---|---|
| East | 120 | 135 | 4 |
After conversion, Excel shows Region, Sales, Sales2 and Column1. To correct them:
- Click the
Sales2header cell and typeSales Q2. Edit the firstSalestoSales Q1for consistency. - Click the
Column1header cell and typeOrders. - Press Enter after each edit. You do not need to press Ctrl+T again.
When you rename a header, Excel updates every structured reference that used the old name. A formula such as =SUM(SalesTable[Sales2]) becomes =SUM(SalesTable[Sales Q2]) without any action from you. This is one of the main benefits of tables over A1-style references. Renaming a header never breaks the formulas that point to it.
Headers with spaces and special characters
Header names are used inside square brackets in structured references. Simple names such as Amount can appear alone: SalesTable[Amount]. A name that contains a space or any of the following characters needs an extra pair of brackets:
- Space, tab, or line break
- Comma, colon, or period
- Brackets, braces, or parentheses
- Quotation marks and
#,$,^,&,*,+,=,-,<,>,/
That is why the Unit Price column is written [@[Unit Price]] and not [@Unit Price]. Excel adds the inner brackets for you when you build a formula by clicking cells. You only need to know the rule when you type formulas by hand.
Four characters have a further rule. If a header contains [, ], #, or ' (an apostrophe), you must put an apostrophe in front of that character inside the reference. A header named Qty [units] is written as:
=SUM(SalesTable[Qty '[units']])This is easy to get wrong, so for tables you plan to reference in formulas, avoid these four characters in headers. Short headers made of plain words and no punctuation are the easiest to maintain.
Showing and hiding the header row
You can turn the header row off without deleting it. Select any cell in the table, open the Table Design tab, and clear Header Row in the Table Style Options group.
The row of header cells is removed from view and the column names are no longer shown in the table. Excel keeps the names internally, so structured references continue to work. If the table is long and the header row is hidden, the column letters at the top of the worksheet show the usual A, B, C labels instead of the names. The filter buttons also disappear, because they live in the header row.
Turn the option back on and the original names return. If you turn the header off and then add a new column, the new column receives a placeholder name such as Column4, and you will need to rename it once the header row is visible again.
Common errors
- Promoted data row. The checkbox was selected when the first row held data. Fix: Ctrl+Z, then recreate the table with the checkbox cleared and add real header text above the range first.
- Unexpected
Column1,Column2names. A header cell was empty, or the checkbox was cleared. Rename them in place. - Numbers shown as text in the header. A year such as
2025is stored as the text"2025". This is correct. Use a prefix such asFY2025if you need to make the intent clear in formulas, or write the reference asSalesTable[2025]. #REF!after deleting a header column. Deleting a table column removes it from the table, so formulas that used its name can no longer resolve. Excel does not rewrite those formulas to anything else.- Merged cells in the header. Excel cannot create a table from a range with merged cells in the header row, and merging after creation is not allowed. Unmerge before you convert, and use one cell per column.
Checking the header row with VBA
The ListObject object exposes the header row directly. This macro reports whether headers are shown and lists the name of each column.
Sub ListTableHeaders()
Dim tbl As ListObject
Dim cell As Range
Set tbl = ActiveSheet.ListObjects("SalesTable")
If Not tbl.ShowHeaders Then
Debug.Print "The header row of " & tbl.Name & " is hidden."
End If
For Each cell In tbl.HeaderRowRange.Cells
Debug.Print cell.Column & ": " & cell.Value
Next cell
End SubShowHeaders is a read/write property, so you can set it to True before reading HeaderRowRange. If the header row is hidden, HeaderRowRange returns Nothing, and the loop would fail. The check above shows that case first, but add an Exit Sub after the message if you reuse this code in a larger macro.
When you create a table with ListObjects.Add, the fourth argument sets the checkbox for you. Use xlYes if the first row holds headers, xlNo if it does not, and xlGuess to let Excel decide as it does in the dialog. Passing xlYes or xlNo explicitly makes the macro behave the same on every sheet.
Checklist before you create a table
- The first row contains one short text label per column.
- No header cell is blank, merged, or contains a formula.
- No two headers are the same.
- Headers avoid
[,],#, and'where possible. - The data below the header has no entirely blank rows or columns inside the block.
- In the Create Table dialog, My table has headers matches what your first row really is.
Exercise
A range has headers Item, Price, Price, and an empty cell in column D, with data below. You create a table from it with My table has headers selected. What are the four header names after conversion, and how would you write a structured reference that sums the column named Unit Cost?
Show answer
The headers become Item, Price, Price2, and Column1. Excel renames the second duplicate and fills the blank cell with a placeholder. A sum of a column named Unit Cost is written =SUM(SalesTable[Unit Cost]). Because the name contains a space, a reference built for a single cell in the same row is written [@[Unit Cost]].
Exercise
You press Ctrl+T on a range whose first row is data, not headers, and you leave My table has headers selected. What happens to that first row, and what should you do?
Show answer
Excel promotes the first data row to the header row, so its values become column names and any numbers or dates in it are converted to text. Press Ctrl+Z, then create the table again with the checkbox cleared. Then rename the placeholder names Column1, Column2, and so on.