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.
Written by Allen Wyatt (last updated January 1, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003
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.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
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 MoreSome types of data may have certain fields that contain partially identical information. In such cases you may want to ...
Discover MoreFilter a large worksheet, and Excel will helpfully recalculate every time you apply a different filter. This can get ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-01-13 10:27:21
Hannu
Sorry "...(2,..." is wrong, add 100 and you will get it correct, this does not work in all situations though (Excel 2013) e.g. in Ribbon: Home -> "Format as Table" at least.
2020-12-10 04:19:35
Willy Vanhaelen
@Eric Gelders
Read carefully the last paragraph, if you want to count cells with text you must use 3 as parameter instead of 2 (equivalent to COUNTA vs COUNT).
2020-12-09 03:58:41
Eric Gelders
The use of SUBTOTAL formula to count the number of lines only works for values, not if there are strings /text in the cells
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments