In Excel: put =ROW()-1 in the first data row and fill it down — the numbers then renumber themselves when rows are inserted, deleted or sorted, which typed numbers do not.
On this page7
Decide first whether the numbers must survive sorting; if so, they should be values, not formulas.
For a dynamic count, put =ROW()-1 in the first data row (adjust the −1 to your header row count).
Double-click the fill handle to run it to the bottom of the adjacent data.
On Microsoft 365 you can instead put =SEQUENCE(ROWS(B2:B500)) in one cell and let it spill.
Inside a Table use =ROW()-ROW(Table1[#Headers]) so new rows number themselves.
To freeze the result, select the column, Ctrl+C, then Paste Special ▸ Values.
What this does
Three methods, and the differences matter. Typing 1 and 2, selecting both and dragging the fill handle produces STATIC numbers: fast, and wrong the moment anyone deletes row 7. =ROW()-1 (subtracting however many header rows you have) is dynamic — delete a row and the rest renumber instantly. =SEQUENCE(ROWS(A2:A500)) in Microsoft 365 spills a whole column of numbers from one formula. There is also a fourth case worth knowing: inside a Table, =ROW()-ROW(Table1[#Headers]) keeps numbering correct as the table grows, because it measures from the header rather than from the top of the sheet. If the numbers must be permanent — an invoice number, a record ID — a formula is the wrong tool: generate them once and paste as values, because an ID that changes when someone sorts the sheet is not an ID. Most people learn this as a sequence of clicks and forget it by next week; learning it as a pattern instead is what lets you apply it to the next, slightly different version of the problem without starting from scratch. That is the difference this page is trying to make. For “number lines in excel”, the reliable version is a short checking loop, not just the first command that appears to work. Run it on a deliberately small range first, watch how the affected cells change, and only then apply the same setup to the full sheet. When a formula is involved, keep the inputs labelled beside it, reference cells instead of typing values, and apply number formatting only after the result checks out. That is what makes a visual that makes the number obvious at a glance useful in real work: repeatable, auditable, and not dependent on memory or luck.
A worked example
Data starts in row 2 under a header. A2: =ROW()-1 → 1, filled down to A500 → 499. Delete row 5 and the column reads 1,2,3,4,… with no gap. Compare with a typed fill: the same deletion leaves 1,2,3,5,6, and nobody notices until a total is quoted against the wrong count. A numbered column is usually there so people can refer to "row 14" in an email — which only works if the number still means the same row tomorrow. A practical tip before you scale it up: build it once on a small block of test data, confirm the number against the tool on this page, and only then point it at your real sheet. That one habit catches almost every mistake while it is still cheap to fix, long before a wrong figure reaches a report or a colleague.
In Google Sheets
Some functions on this page are newer additions to Excel: they are in current Microsoft 365 and Excel for the web, while older perpetual Excel versions return #NAME?. Google Sheets maintains its own function list, so confirm each function exists there before relying on the same formula. Nothing on this page is behind a login or a download: the exact answer is at the top, and the detail below it is there for when you need it. That is the whole promise here — the answer first, and just enough context to make it stick. Treat “number lines in excel” as a small building block rather than a chore. Once the inputs sit in their own cells and the formula reads from them, the same setup answers a dozen related questions with a tweak, and Excel keeps every dependent figure current as the data changes. The tool above is there so you can rehearse and verify before committing anything to a real workbook; the steps and worked example are there so the logic sticks. Get it right once and it stops costing you time — it starts saving it, every time the question comes back around.
Common mistakes
- Typing the numbers and then sorting or deleting rows, leaving a sequence with holes.
- Forgetting to subtract the header rows, so the first data row is numbered 2.
- Using
=ROW()inside a Table and getting sheet row numbers rather than positions within the table. - Using a formula for invoice or record numbers, which then change under sorting — those must be static values.
- Dragging one cell containing 1 instead of two cells containing 1 and 2, which copies 1 all the way down.
Frequently asked questions
How do I number rows in Excel?
Put =ROW()-1 in the first data row and fill down. Subtract as many as you have header rows.
How do I make the numbering update automatically?
Use a formula rather than typed numbers: =ROW()-1, or =SEQUENCE(ROWS(B2:B500)) on Microsoft 365. Both renumber after an insert or delete.
How do I fill a series of numbers?
Type the first two values, select both, and double-click or drag the fill handle. Excel continues the step it infers from the pair.
Why did my numbers stop matching after sorting?
They were typed values, so sorting moved them with their rows. A ROW-based formula recalculates to its new position.