## Summary

To add sequential, automatic row numbers to a set of data with a formula, you can use the ROW function. In the example shown, the formula in B5 is:

``````=ROW()-4
``````

## Generic formula

``=ROW()-offset``

## Explanation

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":

### Row numbers for a named range

The approach for creating sequential row numbers in a table can be adapted to work with a named range like this:

``````=ROW()-ROW(INDEX(data,1,1))+1
``````

Here, we are working with a single named range called "data". To calculate the required offset, we use INDEX like this:

``````INDEX(data,1,1)
``````

We pass the named range data into the INDEX function and request the cell at row 1, column 1. Essentially, we are asking INDEX for the first (upper left) cell in the range. INDEX returns that cell as an address, and the ROW function returns the row number of that cell, which is used as the offset value explained above. The advantage of this formula is that it is portable. It won't break when the formula is moved, and any rectangular named range can be used.

Author

### Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.