Skip to content

ROWS

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()

Lookup and reference

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
A
B
C
D
1
Invoice
Amount
Rows in A2:A9
2
INV-4401
1250
8
3
INV-4402
980
4
INV-4403
2175
5
INV-4404
640
6
INV-4405
1890
7
8
9
10
11

D2 =ROWS(A2:A9) returns 8

How ROWS works

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.

The argument

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.

What it is good for

  • Making a formula adapt to its range size. =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.
  • Counting the results of a dynamic array formula. =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.
  • Counting up while filling down. =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.
  • Averaging or dividing by the number of rows. =SUM(B2:B9)/ROWS(B2:B9) divides by the range size, including blanks. Unlike AVERAGE, it counts empty cells.

ROWS compared with related functions

  • ROW returns the row number of a cell (the position on the sheet). ROWS returns a count.
  • COLUMNS is the equivalent for width.
  • COUNTA counts cells that aren't empty. ROWS counts all of them.

Whole columns

=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).

Errors

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.

Arguments

array
The range, array or array formula to measure, such as A2:A9 or FILTER(A2:C9, C2:C9>100). ROWS counts the rows in its shape, not the cells that hold data.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

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
A
B
C
D
1
Invoice
Amount
Rows in A2:A9
2
INV-4401
1250
8
3
INV-4402
980
4
INV-4403
2175
5
INV-4404
640
6
INV-4405
1890
7
8
9
10
11

D2 =ROWS(A2:A9) returns 8

Example 2

Return the last item of a range

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
A
B
C
D
1
Month
Closing balance
Latest balance
2
Jan
14,200
16,400
3
Feb
15,850
4
Mar
13,900
5
Apr
16,400
6
7
8

D2 =INDEX(B2:B5,ROWS(B2:B5)) returns 16,400

Example 3

Count the results of a FILTER

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
A
B
C
D
E
1
Order
Region
Amount
Orders over 3,000
2
O-701
North
4,200
3
3
O-702
South
1,350
4
O-703
North
2,980
5
O-704
East
760
6
O-705
South
5,120
7
O-706
East
3,340
8
9
10

E2 =ROWS(FILTER(A2:C7,C2:C7>3000)) returns 3

Example 4

A running count that survives inserted rows

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
A
B
C
D
1
No.
Task
2
Order stock
3
Check invoices
4
3
Book carrier
5
Send report
6
7
8

A4 =ROWS($B$2:B4) returns 3

Your turn.

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.

D2
A
B
C
D
E
1
Month
Closing balance
Months listed
2
Jan
14,200
3
Feb
15,850
4
Mar
13,900
Average balance
5
Apr
16,400
6
May
15,100
7
Jun
17,650
8
9
10
11
12

Common mistakes

  • ROWS counts the shape of the range, not the entries in it. 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.
  • If a FILTER returns no matches, it gives #CALC!, and ROWS(FILTER(...)) returns that error instead of 0. Give FILTER an if_empty argument, or wrap it in IFERROR.
  • ROWS needs a reference or an array. A typed-in text argument returns #VALUE!.
  • A range that includes a header row counts the header. ROWS(A1:A9) is 9, even though there are only 8 data rows.

Questions people ask

What is the difference between ROWS and COUNTA?

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.

What is the difference between ROW and ROWS?

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.

How do I count the rows returned by a formula like FILTER or UNIQUE?

Wrap the formula in ROWS: `=ROWS(UNIQUE(A2:A9))`. This works in Microsoft 365 and Excel 2021 or later, where those functions exist.

Does ROWS include hidden rows?

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.

Learn ROWS in a real sheet.

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.