To calculate the row number of a cell in Excel, use the ROW() function. With no argument, =ROW() returns the row number of the cell containing the formula. To get the row number of a specific cell, pass a reference: =ROW(A5) returns 5. For the row number of the current cell relative to a range, combine ROW with ROWS or use =ROW()-ROW($A$1)+1 to get a position within a list.
What You'll Need
- Excel (any modern version: Microsoft 365, Excel 2019, 2021, or Excel for Mac). The ROW function works identically across these versions.
- A worksheet with data or a blank sheet where you can test formulas.
- Basic familiarity with entering formulas (starting with = and pressing Enter).
Step-by-Step
- Open your workbook and click the cell where you want the row number to appear. For example, click cell B1.
- Type the ROW formula. To get the row number of the current cell, type
=ROW(). To get the row number of another cell, type=ROW(A5)(replace A5 with your reference). Press Enter. The result is the row number as a plain number. - Copy the formula down if you need row numbers for a list. Select the cell with the formula, drag the fill handle (small square at the bottom-right corner) down the column. Each cell returns its own row number because ROW() with no argument is relative to the cell it sits in.
- Get a position within a range. If your data starts at row 3 and you want numbering starting at 1, use
=ROW()-ROW($A$3)+1. Copy down. This subtracts the header row offset so the first data row shows 1, the next 2, and so on. - Use ROW with other functions. For example,
=ROW(A10)returns 10. You can nest it:=INDEX(A:A,ROW())returns the value in column A at the current row. This is useful in dynamic formulas. - Check the result. The formula returns a number, not text. If you see a date or a strange value, the cell may be formatted as a date; change the number format to General. Select the cell, right-click, choose Format Cells, and pick General.
- Handle errors. If you see #NAME?, the function name is misspelled. If you see #REF!, the reference is invalid (for example, ROW(A0) or a deleted sheet). Correct the reference and press Enter.
Common Mistakes
- Forgetting the parentheses. ROW is a function; typing
=ROWwithout parentheses returns the #NAME? error. Always use=ROW()or=ROW(reference). - Assuming ROW() returns a fixed number. With no argument, ROW() is volatile in the sense that it changes when you move the formula. If you copy it to another row, the result changes. That is usually desired, but be aware.
- Using ROW to count rows in a range. ROW returns the row number of a single cell, not the number of rows in a range. To count rows, use
=ROWS(A1:A10)which returns 10. - Mixing up ROW and ROWS. ROW gives the row number of a reference; ROWS gives the count of rows in a reference. They are different functions.
- Expecting ROW to work on a closed workbook. ROW requires the workbook to be open; it does not work with external references to closed files in the same way some other functions do.
Tips
- Use
=ROW()in a helper column to create a unique identifier for each row, which is handy for sorting and filtering. - Combine ROW with INDIRECT to build dynamic references, but note INDIRECT is volatile and can slow down large workbooks.
- If you need the row number of the last non-empty cell in a column, use
=MATCH(2,1/(A:A<>""))or=LOOKUP(2,1/(A:A<>""),ROW(A:A))(array formula in older Excel; dynamic arrays in Microsoft 365 handle it natively). - ROW() is not affected by hidden rows or filtering; it always returns the actual worksheet row number. If you need the visible row number after filtering, use SUBTOTAL with a helper column or the AGGREGATE function.
- When copying formulas that use ROW with a reference, use absolute references (e.g.,
ROW($A$1)) if you do not want the reference to shift.
Troubleshooting
If the formula returns an unexpected value, check these in order:
- #NAME? error: The function name is misspelled or the Analysis ToolPak is not enabled (rare in modern Excel). Check spelling: ROW, not ROWS or ROWW.
- #REF! error: The reference points to a deleted cell or sheet. Edit the formula and select a valid cell.
- #VALUE! error: You passed text that cannot be interpreted as a reference. ROW expects a cell reference or range, not a text string like "A5" unless you use INDIRECT.
- Result is a date: The cell is formatted as Date. Change the number format to General or Number.
- Formula shows as text: The cell is formatted as Text, or you typed an apostrophe before the equals sign. Remove the apostrophe and reformat the cell as General, then re-enter the formula.
- ROW() returns the wrong row after inserting rows: This is expected; ROW() is dynamic. If you need a static row number, type the number directly or use a value paste.
If none of these solve it, try re-entering the formula in a fresh cell to rule out a corrupted cell format.
Frequently Asked Questions
What does the ROW function do in Excel?
ROW returns the row number of a reference. With no argument, it returns the row number of the cell containing the formula.
How do I get the row number of a specific cell?
Use =ROW(A5) to get 5. Replace A5 with any cell reference.
Can I use ROW to number rows starting at 1?
Yes. If your data starts at row 3, use =ROW()-ROW($A$3)+1 and copy down.
What is the difference between ROW and ROWS?
ROW returns the row number of a single cell or the first row of a range. ROWS returns the total number of rows in a range.
Why does ROW() return a different number when I copy it?
ROW() without an argument is relative to the cell it is in. When you copy it to another row, it returns that row's number. Use ROW($A$1) for a fixed reference.
Does ROW work with filtered or hidden rows?
ROW always returns the actual worksheet row number, regardless of filtering or hiding. To work with visible rows only, use SUBTOTAL or AGGREGATE.