How to use the ROW function
The ROW function calculates the row number of a cell reference.
Excel Function Syntax
ROW(reference)
Arguments
reference | Optional. A reference to a cell you want to know the row number of. |
Comments
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.
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 click 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.
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
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.
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
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.
Articles with the 'ROW' Function
The following 4 articles have formulas that contain the ROW function.
How to create a list of random unique numbers
Question: How do I create a random list of unique numbers from say 1 to 10, without using VBA and […]
Count overlapping days in multiple date ranges
The MEDIAN function lets you count overlapping dates between two date ranges. If you have more than two date ranges […]
Rearrange cells in a cell range to vertically distributed values
The formula in cell B8 uses a named range to calculate the row and column needed to extract the correct […]
Count cells containing text from list
The array formula in cell F3 counts cells in column B that contains at least one of the values in […]
Functions in 'Lookup and reference'
The ROW function function is one of many functions in the 'Lookup and reference' category.
How to use the ADDRESS function
The ADDRESS function returns the address of a specific cell, you need to provide a row and column number. Formula […]
The AREAS function returns the number of cell ranges and single cells in a reference. Formula in cell B3: =AREAS(E3:E4) […]
How to use the CHOOSE function
The CHOOSE function allows you to retrieve a value based on a number, cell range C3:C4 in the picture above […]
How to use the COLUMN function
The COLUMN function returns the column number of the top left cell of a cell reference. If the argument is not […]
How to use the COLUMNS function
The COLUMNS function allows you to calculate the number of columns in a cell range. The example above shows that cell […]
How to use the FORMULATEXT function
The FORMULATEXT function returns a formula as a text string. Formula in cell C3: =FORMULATEXT(B3) Excel Function Syntax FORMULATEXT(reference) Arguments […]
How to use the HLOOKUP function
The HLOOKUP function lets you search the top row in a data range for a value and return another value […]
How to use the HYPERLINK function
The HYPERLINK function allows you to build a link in a cell pointing to something else like a file, workbook, cell, […]
Gets a value in a specific cell range based on a row and column number.
How to use the INDIRECT function
The INDIRECT function returns the cell reference based on a text string and shows the content of that cell reference. […]
How to use the LOOKUP function
Finds a value in a sorted cell range and returns a value on the same row.
Identify the position of a value in an array.
How to use the OFFSET function
The OFFSET function returns a reference to a range that is a given number of rows and columns from a […]
The ROW function calculates the row number of a cell reference. Excel Function Syntax ROW(reference) Arguments reference Optional. A reference […]
The ROWS function allows you to calculate the number of rows in a cell range. The example above shows that cell […]
How to use the TRANSPOSE function
The transpose function allows you to convert a vertical range to a horizontal range, or vice versa. A vertical range […]
How to use the VLOOKUP function
The VLOOKUP function lets you search the leftmost column for a value and return another value on the same row […]
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.
[…] ROW(reference) Returns the rownumber of a reference […]