Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Counting Filtered Rows.

# Counting Filtered Rows

by Allen Wyatt
(last updated March 19, 2015)

John has applied a filter to the contents of one of his worksheets. He wants to determine the count of rows visible in the filtered data, but when he tries to count them using the COUNT function, Excel returns the overall number of rows, including those not displayed in the filtered list.

This is actually normal behavior—the COUNT function returns all the rows in a range, whether they are visible or not. If you want to determine the number of rows that meet the criteria of your filter, there are a variety of techniques you can use.

If you don't need to get your count in a cell, then you can simply rely upon Excel to inform you of the count. When you apply a filter, the Excel status bar contains a count of how many rows are displayed by the filter. This count disappears as soon as you start editing other information in your worksheet, but it will reappear if you reapply the filter.

You could also select all the visible cells in a particular column and just look in the "totals" area of the status bar. By default Excel displays the sum of whatever cells you've selected, but you can right-click on this sum and instead instruct Excel to display a count of the selected cells.

If you want to use a formula to determine the row count, you could use the COUNTIF function. All you would need to do is make sure that the criteria specified in the function is the same criteria that you used in your filter. The drawback to this, of course, is that if you change your filter criteria you will also need to change the COUNTIF criteria to get an accurate count.

You can also use the SUBTOTAL function to determine the count of rows. For instance, if your filtered information was in A2:A500, you could use this formula to display a count of the rows displayed by the filter:

```=SUBTOTAL(2,A2:A500)
```

The first parameter, 2, indicates that you want Excel to use the COUNT function to determine the formula result. If you change this parameter to 3 then SUBTOTAL will use COUNTA instead. Either way, SUBTOTAL only counts those rows displayed by the filter.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3831) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Counting Filtered Rows.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Editing a Scenario

Once a scenario is defined and saved, you can later revisit the values you created for the scenario and modify them. ...

Discover More

Forcing a Workbook to Close after Inactivity

Tired of your workbooks being left open on the screen where they can be seen by anyone passing by? Here's a way to have ...

Discover More

Changing the Start Screen's Theme

You'll spend a lot of time viewing the Start screen in Windows. If you want to change up things, you can modify which ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

Removing Duplicates Based on a Partial Match

Some types of data may have certain fields that contain partially identical information. In such cases you may want to ...

Discover More

Recalculating when Filtering

Filter a large worksheet, and Excel will helpfully recalculate every time you apply a different filter. This can get ...

Discover More

Excel makes it easy to filter a data table based on various values in that table. It isn't so easy to filter according to ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five more than 3?

2017-09-13 12:21:50

Scott

Any body know how I would Count the number of blank Cells in a filtered table? I know how to count all the blanks in the whole table but when I filter it the number total does not change.

Thanks
Scott

2017-01-20 12:59:11

ROSALINDA

how can I insert a row counter for a filtered list?

2016-12-12 10:03:14

Hisham

i am asking about how to count filtered list to meet specific condition/conditions. ex: function countifs with:
1st, condition "high" in specific column.
2nd, condition "N"in another column.
but the data is filtered so i can no use the function hereunder
=countifs(K1:K150,"high",H1:H150,"N")

2016-02-15 11:35:57

Sharon

I want to count number of blank cells after running a filter

"=LEN(TRIM(A3))=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlGray8
.PatternColorIndex = xlAutomatic
.ColorIndex = xlAutomatic
End With
Selection.FormatConditions(1).StopIfTrue = False
ActiveSheet.Range("\$A\$3:\$W\$26").AutoFilter Field:=7, Criteria1:= _
"John Doe"
Dim mycount As Long
mycount = Application.WorksheetFunction.CountBlank(IFActiveSheet.Range(\$A\$3:\$W\$26)
MsgBox mycount

However by using the above I am getting the total count of blank cells without the filter.
How can I change it in the code above

2016-02-09 07:45:30

Michael (Micky) Avidan

@Rosane Lucero,
Try:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(I1:I1369,ROW(\$1:\$1369)-MIN(ROW(\$1:\$1369)),,1)),N(I1:I1369=1))
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL

2016-02-08 19:39:01

Rosane Lucero

I understand what formula to us to count visible cells when using a filter.

But what formula to I use to count visible cells with specific criteria.

Example of first statement:

=SUBTOTAL(103,A1:A1369)

Example of second statement:
=COUNTIF(I3:I1369,"1")

The second example statement is the one that I really need because the specific criteria needs to be counted; then when re-filtered the amount changes automatically as does in the first example statement.

2016-02-01 06:18:44

Jason

Thank you so much, this is exactly what I was after.

For example "=SUBTOTAL(3,D4:D1648)" in a cell always gives me an indication of the number of filtered rows found.

2016-01-12 04:40:32

shankar

dear sir i had some numerical data sheet, in that i had used below formula to count the values between some range.

=COUNTIF(G7:G8000,">245.00") - COUNTIF(G7:G8000,">249.99")

i just want to know is it possibel to apply this formula while filtering data.

regards,
shankar.

2015-11-06 08:01:10

Paul

Using tables (Excel 2010):

=SUBTOTAL(3, Tablename[columnname])

Works perfectly.

2015-09-11 23:23:43

Sorry, I put wrong formula.
This one is what I made:
=SUMPRODUCT(SUBTOTAL(103,OFFSET(B15,ROW(B15:B723)-ROW(B15),0)),(B15:B723="x")+0)

2015-09-11 23:19:37

Hello,
I have a column with a data and manual filter on that column. I need calcolate count how many "x" in that column but also if I filtering that column it will calculated only quantity "x" in visible row.

=SUMPRODUCT(SUBTOTAL(103,OFFSET(B15,ROW(B15:B723)-ROW(B15),0)),(B15:B723="9")+0)

2015-08-13 10:29:17

Mark

The Subtotals idea worked great for what i wanted to achieve, thanks.

2015-05-22 14:41:00

Angel

"If you don't need to get your count in a cell..." what if I DO need to get my count in each cell?

2015-05-21 04:31:37

Saroj

Saved my day. Thanks.

2015-03-30 18:52:31

lee

i have list of database that have some rows same content, i used filter and remove the same row and keep only one row. But it's take time,i want to export the list of row that displayed in the filter list to a list, could you please help to instruction?
Regards,
Lee

2015-03-18 08:15:42

NDS

This really helped with a macro I was developing where I just wanted a simple way to count how many rows matching a certain criteria had been returned. Thanks!!

2015-02-12 06:27:51

Mohamed Faramawy

Thanks PHILP!
it works very good.

# Column C has data with filter
#in any blank cell I wrote :
=SUBTOTAL(3;C:C)-1

# I minused 1 because of headers are included in subtotal...

2014-12-23 15:20:37

Pleas help me.....
how i cant count, sum many sheets cell in same one product value (one MS Excel file) in only on time.

2014-08-21 17:21:05

Courtney Horrid

This doesn't work. I keep getting zero can someone explain this in a way that gets results.

2013-08-14 15:27:00

PhilP

@ Paul Natolie

As you say =SUBTOTAL(2,T29,T695857) results in 0 (first parameter 2 being Count) - the Count function only 'counts' numbers in a range - you say the list is text.

=SUBTOTAL(3,T29,T695857)(first parameter 3 being CountA) should result in 2 as it 'counts' non-empty cells in a range regardless of number, text or formula.

2013-08-13 07:26:04

Paul Natolie

I tried =SUBTOTAL(2,T29,T695857) but result always returns 0
This is a text list also tried =SUBTOTAL(3,T29,T695857)

What am I doing wrong.

2013-01-20 09:26:32

PhilP

I use =subtotal(102,A:A) in one cell (C1)to tell me how many rows are filtered and =count(A:A) in another cell(B1)to show total rows.

Then conditionally format another cell (A1) by formula (=C1<B1) to show if a filter exists anywhere in the worksheet.

This ACTUALLY WORKS!!

2013-01-19 10:23:38

Marie

Patrick:
Instead of using the actual starting and end cells in the above formula, example A1:A500, just use A:A. Of course, you can't put your subtotal formula anywhere IN column A, or you'd be creating a circular reference.

Keep in mind also, that the value returned by the A:A range is based on everything VISIBLE after a filter is applied, so it doesn't matter how many filters you activate, the number will change as you narrow down your data.

2012-10-23 06:03:18

Barry Fitzpatrick

Function_num....................Function_num Function
(includes hidden values).....(ignores hidden values)
...1................................101...................AVERAGE
...2................................102...................COUNT
...3................................103...................COUNTA
...4................................104...................MAX
...5................................105...................MIN
...6................................106...................PRODUCT
...7................................107...................STDEV
...8................................108...................STDEVP
...9................................109...................SUM
..10................................110...................VAR
..11................................111...................VARP

2012-10-23 05:58:48

Barry Fitzpatrick

In the formula in the article the first parameter should be 102 in order to count only the displayed rows.

The table below shows the values and corresponding functions for the first parameter of the SUBTOTAL function

Function_num Function_num Function
(includes hidden values) (ignores hidden values)
1 101 AVERAGE
2 102 COUNT
3 103 COUNTA
4 104 MAX
5 105 MIN
6 106 PRODUCT
7 107 STDEV
8 108 STDEVP
9 109 SUM
10 110 VAR
11 111 VARP

2012-10-22 12:24:27

Patrick

This seems to require the updating of the cell range every time a filter is changed. Say I have 11,000 rows, and 12 columns. If I set the following A2 A11000, then will get a total of all rows, say 10,998 or so. Then change a filter say Colum 3 filter by state. I would now have say 3,000 rows, but the formula still shows the original. If I change the formula to the new starting and ending row, the formula will now show the proper count. I imagine there is some way to automate this task instead of going back to the formula every time I change a filter. Peanut butter and Jelly reward for a solution. Extra jelly if there is a way to get a second filter to work with the row, say column 3 state filter, and column 4 business team filter.

##### This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.