
Tips.Net > ExcelTips Home > Worksheet Functions > Counting Displayed Cells
Summary: When you filter data, Excel displays only a portion of what is really in a worksheet. If you want to count the number of cells that are displayed after filtering, then you’ll want to explore the techniques in this tip. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)
The AutoFilter feature in Excel makes it easy to display just the information that you want from a data table. How you use AutoFilter has been discussed in other issues of ExcelTips. Once you've applied an AutoFilter to your data, you may want to use a function to display the number of cells that are displayed in a filtered range.
If you just need to quickly know the count, highlight the filtered range, right-click anywhere on the status bar, and choose Count from the resulting Context menu. Excel displays, in the status bar, the number of cells displayed in the range you selected.
If you need a solution that you can use in a formula, you should look towards the SUBTOTAL function. This function provides a number of different "subtotal" results, but it only operates on data that is displayed. This means that the information filtered out by AutoFilter won't count in what SUBTOTAL returns.
The general syntax of the SUBTOTAL function is as follows:
=SUBTOTAL(type,range)
All you need to do is specify a type and a range. The range part should be easy: it is just a standard range. The type specifier can be a number between 1 and 11, as follows:
| Type | Function Performed | |
|---|---|---|
| 1 | AVERAGE | |
| 2 | COUNT | |
| 3 | COUNTA | |
| 4 | MAX | |
| 5 | MIN | |
| 6 | PRODUCT | |
| 7 | STDEV | |
| 8 | STDEVP | |
| 9 | SUM | |
| 10 | VAR | |
| 11 | VARP |
Notice that the type specifier you use indicates what Excel function is applied to the displayed results. Thus, if you want to determine the count of the filtered results in the range of F3:F27, you would use a type specifier of 2, as follows:
=SUBTOTAL(2,F3:F27)
This usage will, of course, count numeric values in the range specified. If you want to count text values, then you should use a type specifier of 3 so that Excel relies on the COUNTA function instead.
If you are the type of person that prefers a macro-based solution, then you may want to refer to the Microsoft Knowledge Base, article 213330 for a fuller discussion:
http://support.microsoft.com/?kbid=213330
Tip #1955 applies to Microsoft Excel versions: 97 2000 2002 2003 2007
PivotTables Got You Perplexed? Learn the ins and outs of this powerful data-crunching tool. ExcelTips: PivotTables for the Faint of Heart makes it easy.
It doesn't matter if you are a beginner or expert, the ExcelTips archives are the fastest way to improve your productivity. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site