← All how-to recipes

How to auto-number rows with a formula

✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)

Row numbers that renumber themselves when rows are added, deleted, or sorted.

The formula

AppFormulaNotes
Excel (desktop)=SEQUENCE(COUNTA(B2:B100))Excel 365: one formula spills numbers for every data row. Universal per-row: =ROW()-1.
Google Sheets=SEQUENCE(COUNTA(B2:B100))Identical.
LibreOffice Calc=SEQUENCE(COUNTA(B2:B100))SEQUENCE needs 24.8+; =ROW()-1 works everywhere.

How it works

SEQUENCE(rows, cols, start, step) generates a number series in one spill โ€” the verified example makes 10, 20, 30 (3 rows starting at 10, stepping 10). For row numbering, SEQUENCE(COUNTA(B2:B100)) sizes itself to the data. The old-school =ROW()-1 filled down also survives inserts/deletes (each cell recomputes its own position) but breaks under sorting โ€” typed literal numbers break under everything, which is why formulas beat typing 1,2,3.

Verified, not just documented

We ran =SEQUENCE(3,1,10,10) in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned 10, 20, 30 — exactly the expected result. We then ran the same formulas in Google Sheets, executed 2026-08-30: a formula-only workbook goes into Google Drive, which converts it to a Sheet and recalculates every formula with Google’s own engine, and comes back out as .xlsx carrying the values Google computed. It returned 10, 20, 30 for the worked example, the same value LibreOffice produced. Both engines’ numbers on this page are executed results. The Excel formula follows Microsoft’s official documented syntax — we do not run desktop Excel.

Functions used

SEQUENCE · COUNTA — see full Excel, Google Sheets & LibreOffice compatibility for each.

Related recipes

Related comparisons