To number rows in Excel, use =ROW()-1 in the first data row and fill down. This returns a sequential count that updates automatically when you insert or delete rows. For a simple static list, type 1 and 2 in the first two cells, select both, and drag the fill handle down. The rest of this guide covers the reliable formulas, how to restart numbering per group, and the mistakes that break a numbering column.
What You'll Need
- Excel 2016 or later, or Microsoft 365 (the steps also work in Excel for Mac and Excel for the web; menu labels can differ slightly by version, device or region).
- A worksheet with your data already entered, ideally with a header row in row 1.
- Basic familiarity with typing formulas and using the fill handle (the small square at the bottom-right of a selected cell).
Step-by-Step
- Decide whether you need a static or dynamic number. A static number is typed once and stays put. A dynamic number is a formula that recalculates when rows are added, removed or sorted. Use a formula unless you are numbering a fixed list that will never change.
- Start with the simplest dynamic formula. Click the first cell of your numbering column (for example A2 if row 1 is a header). Type
=ROW()-1and press Enter. The ROW function returns the row number of the cell, so in row 2 it returns 2, and subtracting 1 gives 1. - Fill the formula down. Select the cell with the formula, then drag the fill handle down to the last row of your data. Alternatively, double-click the fill handle to fill down automatically to the end of the adjacent data. Each row now shows its position in the list.
- Use a counter formula if you prefer. In the first cell type
=COUNTA($B$2:B2), where B is a column that is always filled in your data. Fill down. This counts non-empty cells from the top of the range to the current row, so it numbers only rows that have data in column B. - Number a filtered list without gaps. If you filter your data, ROW-based numbers stay tied to the original row and will show gaps. Use
=SUBTOTAL(103,$B$2:B2)instead and fill down. The 103 argument counts only visible cells, so the numbering re-sequences when you filter. - Restart numbering for each group. If you have a category column (for example C) and want numbering to restart at 1 for each new category, put this in the first data row and fill down:
=COUNTIF($C$2:C2,C2). Each time the value in column C changes, the count starts again at 1. - Convert formulas to fixed numbers if needed. Select the numbering column, press Ctrl+C (Cmd+C on Mac), then right-click and choose Paste Special > Values. This replaces the formulas with plain numbers so they no longer change when the sheet is edited.
- Check the result. Scroll to the bottom of your data and confirm the last number matches the number of data rows. Insert a row in the middle and confirm the formulas renumber correctly (if you used formulas).
Common Mistakes
- Using ROW() without adjusting for the header. In row 2,
=ROW()returns 2, not 1. Subtract the number of rows above your first data row, or start your range in row 1 if there is no header. - Dragging instead of filling. Dragging the fill handle with the mouse can copy the same value if Excel does not detect a pattern. Use the fill handle properly or copy and paste the formula down.
- Hard-coding numbers in a list that changes. Typed numbers do not update when rows are inserted or deleted, leaving duplicates or gaps. Use a formula if the list is likely to change.
- Forgetting absolute references. In
=COUNTIF($C$2:C2,C2), the first reference must be absolute ($C$2) and the second relative (C2). Getting this wrong makes every row count the same range and return identical numbers. - Numbering a filtered list with ROW(). ROW() counts hidden rows too, so filtered views show gaps. Use SUBTOTAL(103,...) for visible-only numbering.
Tips
- Put your numbering formula in a column that is not used for data, and give it a header such as "No." so it is clear what the column does.
- If you need to sort the data later, keep the numbering formula in place; it will renumber automatically after the sort. If you converted to values, the numbers will move with their rows and may no longer be sequential.
- Use
=SEQUENCE(ROWS(B2:B100))in Microsoft 365 to generate a dynamic array of numbers in one step. It spills down automatically and resizes when the range changes. - To number only rows that meet a condition, combine COUNTIFS with an absolute start reference, for example
=COUNTIFS($C$2:C2,"Yes")to count only rows marked Yes. - Format the numbering column as a number, not text, so sorting and calculations behave correctly.
Troubleshooting
- The formula shows as text. The cell may be formatted as Text. Select the column, open Format Cells (Ctrl+1), choose General or Number, then re-enter the formula.
- All rows show the same number. The formula was copied without relative references, or the fill operation copied the value rather than the formula. Re-enter the formula in the first cell and fill down again.
- Numbers have gaps after filtering. You used ROW() or a plain COUNTA. Switch to
=SUBTOTAL(103,$B$2:B2). - Numbers restart unexpectedly. A COUNTIF-based formula restarts when the category value changes. Check for extra spaces or inconsistent capitalization in the category column, which Excel treats as different values.
- #REF! or #VALUE! errors. A referenced column may have been deleted, or the formula contains text where a number is expected. Check the references and re-enter the formula.
- Numbers do not update after inserting rows. The formulas may have been converted to values. Re-enter the formula and fill down again.
Frequently Asked Questions
What is the formula to number rows in Excel?
The simplest is =ROW()-1 in the first data row, filled down. It returns 1, 2, 3 and so on, and updates when rows are inserted or deleted.
How do I number rows without gaps after filtering?
Use =SUBTOTAL(103,$B$2:B2), where B is a column that is filled for every data row. The 103 argument counts only visible cells, so the sequence stays continuous in a filtered view.
How do I restart numbering for each group?
Use =COUNTIF($C$2:C2,C2), where C is the group column. Each new group value starts the count again at 1.
Can I number rows automatically when I add new data?
Yes. A formula such as ROW()-1 or COUNTA recalculates when rows are added, provided the formula is filled down far enough or converted to an Excel Table, which extends formulas automatically.
Why does my numbering show the same number in every row?
The formula was likely copied as a value or the references were made absolute. Re-enter the formula in the first cell with relative references and fill down again.
How do I convert numbering formulas to fixed numbers?
Select the column, copy it, then use Paste Special > Values. The formulas are replaced with their current results and will no longer update.