New: ready-to-use spreadsheet templatesExplore the collection  →
PASTE-READY RECIPE

Number Rows Automatically in Google Sheets

Generate row numbers only when the row contains data.

Written by PhilisPublished July 27, 2026Updated July 27, 2026Visual demo planned
QUICK ANSWER

The formula and where it fits.

Generate row numbers only when the row contains data. Use =ARRAYFORMULA(IF(B2:B="","",ROW(B2:B)-ROW(B2)+1)), then replace the sample ranges with the columns in your sheet.

ROW creates the sequence; IF leaves unused rows empty.

  1. Put the source data under one header row.
  2. Paste the formula into an empty result cell.
  3. Change the ranges and criteria to match your sheet.
  4. Check the result against one row you can verify manually.
TRY IT

Edit the table.
Watch the result change.

EDITABLE INPUT DATA
fx=ARRAYFORMULA(IF(B2:B="","",ROW(B2:B)-ROW(B2)+1))
A
1Task
2
3
4
5
FORMULA OUTPUT1 · 2 · blank · 4Recalculates from the input cells above
VARIATIONS

Use the version that fits your sheet.

01

Continuous numbers without gaps

=ARRAYFORMULA(IF(B2:B="","",MATCH(ROW(B2:B),FILTER(ROW(B2:B),B2:B<>""),0)))

Counts only filled rows.

02

SEQUENCE

=SEQUENCE(COUNTA(B2:B))

Creates a compact list from 1 to the count.

03

Start at 1001

=ARRAYFORMULA(IF(B2:B="","",ROW(B2:B)-ROW(B2)+1001))

Uses a custom starting number.

COMMON ERRORS

When the result looks wrong.

Numbers appear beside blank-looking formulas

Test B2:B="" rather than COUNTA when source formulas return empty text.

Sorted rows keep old manual numbers

Use the array formula rather than typed numbers.

QUESTIONS

Answers before you paste.

Numbers appear beside blank-looking formulas

Test B2:B="" rather than COUNTA when source formulas return empty text.

Sorted rows keep old manual numbers

Use the array formula rather than typed numbers.

MAKE IT YOURS

Change the ranges, labels or criteria.

Send this recipe to the SheetSteps assistant and describe how your columns are arranged.

Adjust this formula