# How to use the ROW function

The ROW function calculates the row number of a cell reference.

**What is on this page?**

## 1. ROW Function Syntax

ROW(*reference*)

## 2. ROW Function Arguments

reference |
Optional. A reference to a cell you want to know the row number of. |

The ROW function is one of my most used Excel functions, that you probably already know if you have been browsing around my web site.

The first example demonstrates basic usage. Example 2 and 3 are more advanced and requires some knowledge about MATCH and INDEX function.

## 3. Example 1 - Cell references

You can enter a reference to a single cell or a cell range in the ROW function. Note that it will return an array of numbers if you enter a reference to a cell range, as long as you enter it as an array formula.

Formula in cell B2:

B2 is a relative cell reference meaning it changes when you copy the cell and pastes it to another cell.

ROW(B2)

returns 2.

Formula in cell B6:

This example shows that you can omit the argument, the formula will default to the cell where the formula is entered.

The formula is entered in cell B6 in the example above, so it returns 6.

Formula in cell B11:

$D$10 is an absolute cell reference meaning it won't change if you copy the cell and paste to other cells. Absolute and relative references in Excel

returns 10.

The following example is not demonstrated in the image above. Type this formula in any cell:

To enter the formula as an array formula, follow these steps: Press and hold CTRL + SHIFT simultaneously, then press Enter. Release all keys.

The formula is now surrounded by curly brackets, like this: {=ROW(A2:A5)}. Don't enter these characters yourself, they appear automatically.

The cell will now only show the first value in the array which is 2, you must enter the array formula in a cell range equal of size as there are values in the array to be able to see them all.

**Update - Dynamic arrays**

Office 365 subscribers can now take advantage of dynamic arrays. They behave differently than regular array formulas, simply enter them as a regular formula and Excel will automatically extend the formula to cells below so you can see all values.

This behavior is called spilling, see image above. The cell range containing spilled values have a blue border, it will disappear as soon as you press with left mouse button on outside the cell range.

Microsoft recommends that you use dynamic arrays instead of regular array formulas, however, they are still working and compatible with older Excel versions.

## 4. Create an array of sequential numbers

The image above demonstrates a formula that creates an array of sequential numbers from 1 to 4. This can be used to number any cell range in order to get the appropriate values/rows.

Here are a few examples: Extract all rows from a range that meet the criteria in one column | 5 easy ways to VLOOKUP and return multiple values | INDEX MATCH - partial match multiple columns

Excel 365 subscribers can use the SEQUENCE function which offers more granular control. Most Excel 365 functions don't need the SEQUENCE function to number values/rows. For example, the FILTER function keeps track of values by itself.

Array formula in cell B2:

### 4.1 How to enter an array formula

- Select cell range B2:B5 with your mouse.
- Type: =ROW(A1:A4)
- Press and hold CTRL + SHIFT keys simultaneously.
- Press Enter once.
- Release all keys.

The formula in the formula bar has a leading and ending curly bracket, they appear automatically when you follow all 5 steps above.

Don't enter these characters yourself.

## 5. Example 2 - Duplicate columns in an array

This example demonstrates that if you provide a cell reference pointing to a cell range containing multiple columns the formula will still only return a single column of row numbers.

returns this array {3; 4; 5}.

The semicolon is a separating character telling you that the values are on a row each. A comma is used to separate values distributed across columns.

Now you might wonder why the array formula doesn´t return {3, 3; 4, 4; 5, 5}. There are six cells in the cell range, how come only three values are returned?

The answer is that there is no need for multiple **duplicate** columns in the array. Excel simplifies the array down to a single column.

But when used with multiple cell ranges in more complicated array formulas, make sure the number of rows matches.

See this example: Unique distinct values from a cell range

## 6. Example 3 - Number rows in any cell range

The INDEX function returns a value of the cell at the intersection of a particular row and column, in a given range. To be able to work with multiple values from an arbitrary cell range using the INDEX function we must **number each row**.

That is exactly what we did in the previous example but the first row in a given range has to be 1 and the second 2 and so on. Why? The INDEX function needs properly numbered cell ranges. This is where the ROW and MATCH function comes in.

*cell_range*), ROW(

*cell_range*))

The beauty with this formula is that it returns row numbers from any cell range no matter size or location.

Array formula in cell range B3:B5:

becomes =MATCH({3; 4; 5}, {3; 4; 5}) and returns {1; 2; 3}. This array has the same number of values as there are rows in cell range C3:D5.

Remember, enter the formula as an array formula.

So what can you do with row numbered cell ranges?

The MATCH function can also be used to find the relative position of a value in a cell range. See these posts:

- How to extract unique distinct values from a column

- Repeat values
- Fetch data from another table
- Shift Schedule

## 7. How to number rows?

The image above demonstrates how to number records in a data set, however, this method is not great and I will show you why.

Here are the steps:

- Select cell B3.
- Type: =ROW(A1)
- Press Enter.
- Copy cell B3.
- Paste to cells below as far as needed.

Why not use this formula? The formula will break if you insert more rows above, the cell reference is relative meaning it will change. The same thing will happen with an absolute formula.

I recommend you use the ROWS function with an expanding cell reference.

Formula in cell B3:

Copy cell B3 and paste to cells below, this will adjust the expanding cell reference accordingly. This will not break if you insert more rows.

### 'ROW' function examples

First, let me explain the difference between unique values and unique distinct values, it is important you know the difference […]

This post explains how to lookup a value and return multiple values. No array formula required.

This blog article describes how to split strings in a cell with space as a delimiting character, like Text to […]

### Functions in 'Lookup and reference' category

The ROW function function is one of 25 functions in the 'Lookup and reference' category.

### Excel function categories

### Excel categories

### One Response to “How to use the ROW function”

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form

[…] ROW(reference) Returns the rownumber of a reference […]