To add sequential row numbers to a set of data with a formula, you can use the ROW function. See example below:
In the example shown, the formula in B5 is:
How this formula works
When not given a reference, the ROW function returns the row number of the current row. In cell B5, ROW returns 5, in cell B6, ROW() returns 6, and so on:
=ROW() // returns 5 in B5 =ROW() // returns 6 in B6
So, to create sequential row numbers beginning with 1, we subtract 4:
=ROW()-4 // returns 1 in B5 =ROW()-4 // returns 2 in B6
This formula will continue to work as long as rows are not added or deleted above the first row of data. If rows are added or deleted above the data, the hardcoded offset value 4 will need to be adjusted as needed.
Row numbers in a Table
If we convert the data to a proper Excel Table we can use a more robust formula. Below, we have the same data in “Table1”:
The formula in B5, copied down, is:
Here, instead of subtracting a hardcoded offset, we calculate the correct offset with this expression:
Because the ROW function returns the the first row of table data (not including the header), we need to add 1 to start row numbering at 1. This formula will continue to work correctly when the table is moved, or when rows are inserted or deleted above the table.