Example 1
Count the rows in a range
D2 =ROWS(A2:A9)
Result: 8
The range A2:A9 has eight rows, even though only five of them hold data. ROWS measures the shape, not the content.
D2 =ROWS(A2:A9) returns 8
Returns the number of rows in a range or array, whether or not the cells are filled. Use it to size a range, find the last item or count the results of a formula.
Syntax
=ROWS()
Every version of Excel, including Microsoft 365, Excel 2024, 2021, 2019, 2016 and earlier, Excel for the web and the mobile apps.
Try it
Edit the formula in D2 or change the inputs. The sheet recalculates as you type.
D2 =ROWS(A2:A9) returns 8
ROWS returns how many rows a range or array has. =ROWS(A2:A9) returns 8, whether those cells are full, empty or a mix. It measures the shape of the range, which is the difference between ROWS and the counting functions.
array is a cell range, an array constant such as {1;2;3}, or the result of a formula that returns an array. For a single cell, ROWS returns 1.
ROWS doesn't look at what is in the cells. To count filled cells use COUNTA, to count numbers use COUNT, and to count blanks use COUNTBLANK. Use ROWS when you want the size of the block itself.
=INDEX(B2:B9, ROWS(B2:B9)) returns the last item of the range, and if you extend the range to B2:B20, both references can be updated together. Counting with ROWS keeps the INDEX and the range tied to the same block.=ROWS(FILTER(A2:C9, C2:C9>100)) counts the matching rows. =ROWS(UNIQUE(A2:A9)) counts the distinct values. Both work in Microsoft 365 and Excel 2021 or later.=ROWS($A$2:A2) returns 1 in the first row and 2 in the next, because the end of the range moves as you fill down. It is a numbering method that doesn't depend on where the table sits on the sheet, unlike ROW. If you insert rows above the table it still gives 1, 2, 3.=SUM(B2:B9)/ROWS(B2:B9) divides by the range size, including blanks. Unlike AVERAGE, it counts empty cells.=ROWS(A:A) returns 1,048,576, the number of rows on a worksheet, not the number of rows with data. To count entries, use COUNTA(A:A).
ROWS returns #VALUE! if its argument isn't a reference or an array, such as plain text typed into the formula. If the argument is itself an error, such as a formula that returned #N/A, ROWS returns that error.
A2:A9 or FILTER(A2:C9, C2:C9>100). ROWS counts the rows in its shape, not the cells that hold data.Each example is a live sheet. Change the inputs or the formula and watch the result.
Example 1
D2 =ROWS(A2:A9)
Result: 8
The range A2:A9 has eight rows, even though only five of them hold data. ROWS measures the shape, not the content.
D2 =ROWS(A2:A9) returns 8
Example 2
D2 =INDEX(B2:B5,ROWS(B2:B5))
Result: 16,400
ROWS(B2:B5) is 4, so INDEX returns the fourth item. This works when the range is filled to the end. If the range has empty cells at the bottom, use a lookup for the last number instead.
D2 =INDEX(B2:B5,ROWS(B2:B5)) returns 16,400
Example 3
E2 =ROWS(FILTER(A2:C7,C2:C7>3000))
Result: 3
FILTER returns the orders over 3,000 as a block of three rows, and ROWS counts them. If nothing matches, FILTER returns #CALC! and so does ROWS, so wrap it in IFERROR when that can happen.
E2 =ROWS(FILTER(A2:C7,C2:C7>3000)) returns 3
Example 4
A4 =ROWS($B$2:B4)
Result: 3
The range starts at the first task and ends at the current row, so it has 3 rows in the third task. Filled down from A2, the formula gives 1, 2, 3 and so on, wherever the table sits on the sheet.
A4 =ROWS($B$2:B4) returns 3
Solve it in the sheet. Every answer is checked, with hints if you need them.
Task 1 of 2
In D2, return the number of months listed in A2:A7, using a function that measures the size of the range.
Answer in D2.
ROWS(A2:A100) is 99 even if only 5 cells hold data. Use COUNTA to count entries.ROWS(A:A) is 1,048,576, the full height of the worksheet. It is almost never what you want.#CALC!, and ROWS(FILTER(...)) returns that error instead of 0. Give FILTER an if_empty argument, or wrap it in IFERROR.#VALUE!.ROWS(A1:A9) is 9, even though there are only 8 data rows.ROWS counts every row in a range, filled or not. COUNTA counts only the cells that aren't empty. For `A2:A9` with five entries, ROWS returns 8 and COUNTA returns 5.
ROW returns the row number of a cell: `ROW(C5)` is 5. ROWS returns how many rows a range has: `ROWS(C5:C9)` is 5.
Wrap the formula in ROWS: `=ROWS(UNIQUE(A2:A9))`. This works in Microsoft 365 and Excel 2021 or later, where those functions exist.
Yes. ROWS counts the rows in the shape of the range, whether they are hidden, filtered out or empty. To count only visible rows use SUBTOTAL or AGGREGATE.
ROWS is taught in Data analysis with formulas, lesson 12: UNIQUE: lists and distinct counts. Each lesson is a short, graded exercise like the one above.