Loading
Excel.Tips.Net ExcelTips (Menu Interface)

Counting Filtered Rows

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.

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.

Related Tips:

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

 

Comments for this tip:

Courtney Horrid    21 Aug 2014, 17:21
This doesn't work. I keep getting zero can someone explain this in a way that gets results.
PhilP    14 Aug 2013, 15:27
@ 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.


Paul Natolie    13 Aug 2013, 07:26
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.

PhilP    20 Jan 2013, 09:26
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!!
Marie    19 Jan 2013, 10:23
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.
Barry Fitzpatrick    23 Oct 2012, 06:03
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
Barry Fitzpatrick    23 Oct 2012, 05:58
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
Patrick    22 Oct 2012, 12:24
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.

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 4+5 (To prevent automated submissions and spam.)
 
          Commenting Terms
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2013)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2013)

Our Products

Premium Newsletters

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2014 Sharon Parq Associates, Inc.