Spreadsheet Practice

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

Formula (Excel and Google Sheets)

=XLOOKUP(TRUE,B2:G2<>"",B$1:G$1)

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

Result on the example
one result per row in H2, filled down to H6
Works in
Excel 2021, 2024 and Microsoft 365
Google Sheets
Same formula

See it work

The formula is already in H2, filled down to H6. Change any input and the result updates, or edit the formula to experiment.

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.

=XLOOKUP(TRUE,B2:G2<>"",B$1:G$1)

Result"Feb"

  1. B2:G21 row × 6 cols: (empty), 42, 66, 58, …

    A range: 6 cells in one row.

  2. B2:G2<>""{1 row × 6 cols} FALSE, TRUE, TRUE, TRUE, …

    The <> operator tests whether they differ.

  3. B$1:G$11 row × 6 cols: "Jan", "Feb", "Mar", "Apr", …

    A range: 6 cells in one row.

  4. XLOOKUP(TRUE,B2:G2<>"",B$1:G$1)"Feb"

    XLOOKUP: Searches one range and returns the matching item from another.

    • lookup_valueTRUE
    • lookup_arrayB2:G2<>""{1 row × 6 cols} FALSE, TRUE, TRUE, TRUE, …
    • return_arrayB$1:G$11 row × 6 cols: "Jan", "Feb", "Mar", "Apr", …

In Google Sheets

The same formula works in Google Sheets: =XLOOKUP(TRUE,B2:G2<>"",B$1:G$1). We ran it in Google Sheets mode on the same data and it returns the same results.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=INDEX(B$1:G$1,MATCH(TRUE,INDEX(B2:G2<>"",0),0))Feb, Mar, Feb…Every Excel version, without Ctrl+Shift+Enter.
=XLOOKUP(TRUE,B2:G2<>"",B$1:G$1,,0,-1)Apr, Jun, Apr…Different resultSearch 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").

Try it yourself

Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.

Return the column header of the first non-blank cell

The table shows hours logged per month. In H2, return the month each project started (the header above its first filled cell), then fill down to H6.

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.

Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.