# How to return the column header of the first non-blank cell in Excel

Return the header row instead of the values: `=XLOOKUP(TRUE,B2:G2<>"",B$1:G$1)`.

**Excel:** `=XLOOKUP(TRUE,B2:G2<>"",B$1:G$1)` (Excel 2021, 2024 and Microsoft 365)

**Google Sheets:** the same formula works.

## Example

Sample data (row 1 is the header):

| A | B | C | D | E | F | G | H |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Project | Jan | Feb | Mar | Apr | May | Jun | Start month |
| Website redesign |  | 42 | 66 | 58 |  |  |  |
| CRM migration |  |  | 35 | 80 | 74 | 40 |  |
| Brand refresh |  | 24 | 30 | 18 |  |  |  |
| Data warehouse |  |  |  |  | 52 | 96 |  |
| Mobile app | 16 | 40 | 88 | 92 | 75 | 60 |  |

Formula in H2, filled to H6: `=XLOOKUP(TRUE,B2:G2<>"",B$1:G$1)`

Result: Feb; Mar; Feb; May; Jan

## How it works

The test `B2:G2<>""` marks the months with hours. XLOOKUP finds the first TRUE and returns the item in the same position of the header row `B$1:G$1`. The `$` keeps the header row fixed while the formula fills down.

## Other ways

- `=INDEX(B$1:G$1,MATCH(TRUE,INDEX(B2:G2<>"",0),0))`: Every Excel version, without Ctrl+Shift+Enter.
- `=XLOOKUP(TRUE,B2:G2<>"",B$1:G$1,,0,-1)`: Search from the right for the last month with hours, the end month. (The last month with hours instead of the first.)

## Common mistakes

- Without `$` on the header row, it moves down as you fill and returns the wrong labels.
- A project with no hours at all returns #N/A. Add a message as the 4th argument: `XLOOKUP(TRUE,B2:G2<>"",B$1:G$1,"Not started")`.

## Questions

**How do I count the months between start and end?**

Use the positions: `=XMATCH(TRUE,B2:G2<>"",0,-1)-XMATCH(TRUE,B2:G2<>"")+1`.

**What if the headers are dates?**

The same formula returns the date; give the result cells a date format.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/header-of-first-non-blank-cell
