← All how-to recipes

How to auto-number rows with a formula

✓ Verified in LibreOffice 25.8.7.3

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

The formula

AppFormulaNotes
Excel=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. Every formula here is confirmed by actually executing it.