Home > Formulas > Count > Examples Excel Count FunctionsExcel Count formula examples. Count filtered rows. COUNTIF one or more criteria. Count numbers, text, blank cells. Short videos, Excel files, written steps 
Overview: 7 Ways to Count in ExcelTo see a quick overview of 7 ways to get a total count of cells in Excel, watch this short video. There are written steps for each count function below the video. 
Count Numbers, All Data, or Blank CellsThis video shows the COUNT function, the COUNTA function, and the COUNTBLANK function, and warns of the quirks in counting some types of cells. Written instructions are below the video. Count Cells with Numbers, Count Cells with Data and Count Blank Cells. Also, get the sample workbook, to see all the formulas. 
COUNT Function ResultsTo verify the count, I used the COUNT function in cells B2:B7, to count each item in column A.
Verify with ISNUMBERFor a different verification method, I use the ISNUMBER function in column C, to check each value in column A.

COUNTBLANK: Count Blank CellsThe COUNTBLANK function will count cells that are empty (blank), and cells that contain an empty string
Use COUNTBLANK FunctionTo count cells that are completely empty, use the Excel COUNTBLANK function, which has the following syntax, with one argument  range:
Follow these steps, to count the blank cells in the worksheet range A1:A5:
In this example, the formula result is 1, becasue there is one completely empty cell in the range. 
Cells Look Blank  Empty StringsThe COUNTA and COUNTBLANK functions will both count cells that contain empty strings (also called empty text). For example, in the screen shot below, the following formula returns an empty string (""), if cell A3 is not an odd number:
Cells B3 and B5 look empty, because the formula result in those cells is an empty string. Counting Empty StringsIf you're counting the same range of cells with different functions, be careful that you aren't counting "empty string" cells twice. In the example shown above, the empty string cells are counted by the formulas in cells B8 and B9.
Empty String Cells Without FormulasIf you import data to Excel, such as query results from Microsoft Access, some cells might look empty, but Excel treats them as containing empty strings. Also, some data created within Excel can contain empty strings, with no formulas. Those cells are usually created by copying a range where some formulas returned an empty string, then pasting those cells as values.
To fix cells that look blank, but are being counted, see my Contextures blog: Fix Blank Excel Cells Copied From Database 
COUNTIF: Count with one criterionThis video shows how to use the Excel COUNTIF function to count cells that contain a specific string of text, such as "Pen". You can also find text that is part of a cell  how many orders were placed for any kind of pen, such as "Gel Pen", "Pen" or even a "Pencil"? The written steps for the Excel COUNTIF function examples are below the video: 1) Match criterion exactly and 2) Match criterion in a string 
1) COUNTIF: Exact Match  One criterionIn an Excel spreadsheet, count cells that are an exact match for one specific criterion. In this example only the Pen orders, with an exact match for the criterion, will be counted.

2) COUNTIF: Partial Match  One Criterion in a stringIn Excel, count cells that contain a criterion as part of the cell's contents  a partial match. In this example all Pen, Gel Pen, and Pencil orders will be counted, because they contain the string "pen".
Note: Instead of typing the criterion in a formula, you can
refer to a cell. For example, the formula in step 7 above could be
changed to: 
Count cells that match multiple criteriaThis video shows how to use the COUNTIFS function to count cells based on multiple criteria. Written instructions are below the video: Count multiple criteria with COUNTIFS Count multiple criteria with SUMPRODUCT Count all dates in a specific month and year 
Count Numbers with CriteriaIn this video, see how to use COUNTIF function to count the number of items in a list that are over or under a specific amount. Written instructions are below the video: 
Count Cells Greater Than or Equal toYou can use an operator with a criterion. In this example only the rows where the quantity is greater than or equal to ten will be counted.
Note: Instead of typing the criterion in a formula, you can
refer to a cell. For example, the formula in step 8 above could be
changed to: Or, you could use a function as part of the criterion. For example: 
Count Numbers Between Min and MaxTo count numbers in a specific range, such as "between 5 and 10", you can use either:
There is an example for each function in the sections below, and notes on using cell references for the minimum and maximum numbers, instead of typing them in the formulas. Note: I recommend using COUNTIFS, for Excel 2010 and later, because the formula is shorter, and easier to understand. 1) Count Numbers in Range  COUNTIFSIn this example, the COUNTIFS formula will count rows where the number in column B is between 5 and 10 (inclusive). Enter the following formula in the cell where you want the count  I used cell B12 in the screen shot below. The criteria and operators are enclosed in double quote marks.
The formula result is 6, because there are six product sales with quantity that meets the two criteria:
2) Count Numbers in Range  COUNTIFTo get the count with the COUNTIF function, you'll need a formula that uses 2 instances of COUNTIF. Just like the COUNTIFS example shown above, this COUNTIF formula will count rows where the quantity is between 5 and 10 (inclusive). Enter the following formula in the cell where you want the count  I used cell B12 in the screen shot below. The criteria and operators are enclosed in double quote marks.
The formula result is 6, because there are:
Cell References for CriteriaInstead of typing the criterion in a formula, you can refer to a worksheet cell, where the criteria values are stored. This makes it easier to adjust the number range  you don't have to modify the formula, just the worksheet cells. For example, the COUNTIFS formula above could be changed to:
In this example:

Count  Multiple Criteria  Other FunctionsIn addition to COUNTIFS, you can use other Excel functions for advanced counting formulas  1) Count Cells  Multiple Criteria  SUMPRODUCT  2) Count Dates  Specific Month and Year 1) Count Cells  Multiple Criteria  SUMPRODUCTIn this example, the SUMPRODUCT function is used to count the rows where the item is "Pen" and the quantity is greater than or equal to ten. This solution will work in older versions of Excel, where there COUNTIFS function is not available.
Note: Instead of typing the criterion in a formula, you can refer to a cell, as shown in the second formula below ▲TOP Use typed criteria: =SUMPRODUCT((A2:A10="Pen"),(B2:B10>=10)) or cell references: =SUMPRODUCT((A2:A10=D2),(B2:B10>=E2)) 
Change Operator for COUNTIF FunctionInstead of typing the operator into the COUNTIF formula, as shown above, you can create a list of all possible operators, and select one from a drop down list. Then, refer to that operator in the formula. This video shows the steps for setting up the formula, and the written instructions are below the video. Create a Drop Down List of OperatorsTo create a drop down list operators:
Use the Drop Down ListChange your COUNTIF formula, to replace the typed operator with a reference to the cell with the drop down list. =COUNTIF(B2:B11,E6&F6) Then, select one of the operators from the drop down list in cell E6, and the formula result will change. 
Count Numbers in NumbersThe COUNTIF function can find specific letters or numbers in a text string. However, COUNTIF cannot find a specific number within a real number. In the screen shot below, there are 4 items in the list that contain a "1". The COUNTIF formula in cell A9 gives an incorrect result of 3. It does not count the "1" in cell A2, because that cell contains a real number, not a text string. Use FIND or SEARCHAlthough the COUNTIF function can't count specific numbers within real numbers, the FIND or SEARCH function will locate them. In the screen shot below, the following formulas are used in columns C, D and E, to look for a "1". The ISNUMBER function returns True or False, and the two minus signs (double unary) convert True to 1 and False to 0 (zero).
The FIND and SEARCH formulas found all 4 items that contain a "1". The COUNTIF formula only found 3 items. Use SUMPRODUCT with FIND or SEARCHInstead of checking each row individually, use the SUMPRODUCT function with FIND or SEARCH, to get the total count for the list.

Example 1: NumbersIn this example, the formulas give a count of cells that contain a 1. The result is 4 in both cases.
Example 2: LettersIn the next example, the formulas give a count of cells that contain "a". FIND only counts the lowercase "a" (1), and SEARCH counts both the uppercase "A", and lowercase "a" (2).

Count Rows in Filtered List  SUBTOTALAfter you filter the rows in a list, you can use the SUBTOTAL function to count the visible rows in the filtered data.
SUBTOTAL Syntax
In the SUBTOTAL function syntax, there are two required arguments:
SUBTOTAL ExampleIn this example, there is a list on the worksheet, from cell A1 to D10. In column A, a filter has been applied, to show Binder Items only. In cell A12, the following formula is entered:
SUBTOTAL FormulaIn the above formula:
Filtered or Manually HiddenIn the first set of function numbers for the SUBTOTAL function, only the rows hidden by filtering are ignored. If you also want to ignore rows that were manually hidden, use the "100range" numbers instead. In the screen shot below:

Count Rows in Filtered List With AGGREGATEAfter you filter the rows in a list, you can use the AGGREGATE function to count the visible rows. This function was introduced in Excel 2010, and is similar to SUBTOTAL, but it has 19 functions, compared to SUBTOTAL's 11 functions. Another advantage is that it can ignore errors, as well as hidden rows.
The two visible numbers are counted, and the error in cell D9 is ignored. 
Count Specific Items in a Filtered ListLaurent Longre created a formula that lets you work with visible rows
after a filter. For information see, Power Formula Technique in this
article at John Walkenbach's web site (via the WayBack Machine site): Incorporating that technique, SUMPRODUCT can be used to count visible items in a filtered table. In the following example, column D has been filtered for amounts greater than 100. The following formula will count the number of visible rows that contain "Pen" in column A.
=SUMPRODUCT(SUBTOTAL(3,OFFSET(A1:A10,ROW(A1:A10)

Count Unique Items in a Filtered ListHere are two ways that you can count the number of unique items in a filtered list:
1) Helper Columns for Unique Visible Item CountThanks to Alex J who shared his technique for counting the unique visible items in a filtered list. In the screenshot below, the formula in column D shows a 1 for the first instance of each item, and a 0 for all subsequent instances. For example, in cell D7, there’s a 1, counting item 91AB145, and in the next two rows the count for the same item is zero. The formula in cell D5 is: =(COUNTIF($C$5:$C5,$C5)<2)*1 Apply a FilterHowever, when the list is filtered to show only the Central region items, the total in cell D2 still shows 16 unique items, and cell D11 shows a zero for item 91AB146, even though it’s the first visible instance of that item. To solve the problem, AlexJ added some helper columns to the table. First, in column E, he created a formula to check if the row is visible. The formula in cell E5 is: =1*SUBTOTAL(3,$D5) AlexJ uses the 1 multiplier at the start of the formula to avoid the problem of the last row not being included in the AutoFilter range. Based on this new formula, the total in cell E2 correctly shows that only 6 rows are visible. Test For Visible RowsNext, in column F, AlexJ created a formula to show the item name if the row is visible. For hidden rows, the formula displays a hyphen instead of the item name. In cell F5, the formula is: =IF($E5,$C5,”“) In cell G1, I tested the result for hidden cell F6, and you can see the result is a hyphen. Count Unique Visible ItemsFinally, in column G, AlexJ created a formula to check for unique items in column F, where only the visible rows have an item name. In cell G5, the formula is: =($F5<>”“)*(COUNTIF($F$5:$F5,$F5)<2) With this formula, the hidden rows are ignored, and the count of unique items in cell G2 is correct for the filtered rows. The item 91AB145 is counted only once, even though it’s in the filtered results twice, and item 91AB146 is counted, even though it’s not the first instance of that item in the full list. 2) Array Formula for Unique Visible Item CountIn the Excel Expert Newsletter (issue 20, July 8, 2001  no longer available), there is a formula to count unique items in a filtered list. In this example, the list is filtered to show only the Central region, and unique visible items in column D are counted.

Count Duplicated Items in ListIn this example, there is a formula to check a column that should contain unique values only. It will alert you if any of the values have been duplicated. In cells A6:C12, there is a named table (tblIDs). In the ID column, each number should be unique, but 2 is entered twice, and 3 is entered twice. The formula shown below will count how many unique values have been duplicated.

Formula to Count Duplicated ItemsDuplicate ID numbers could cause problems, so we'll create a formula to check for them. To count the duplicated values, enter this formula in cell A4. The details are below: =SUMPRODUCT((tblIDs[ID]<>"") / NOTE: To simply highlight duplicate values in a column, use Conditional Formatting. How It WorksThe SUMPRODUCT formula contains 3 formulas:
Next, A is divided by B, and C is subtracted Finally, those results are summed, to give the count of duplicated values. 
Calculate in the Formula BarIn the formula bar, you can select each formula (A, B, and C), and press F9 to calculate that formula. This screen shot shows the results. Then, calculate the A/B portion of the formula, to see these results. TRUE is equal to 1, so 1/1 equals 1, and 1/2 equals 0.5. Next, calculate A/B  C, to see these results. TRUE is 1 and FALSE is zero, so 11 equals zero, and 0.5  0 equals 0.5: Finally, the SUMPRODUCT function gives the sum of those numbers, with the result of 2. 
Worksheet FormulasYou can see the same results if you put each part of the formula on the worksheet, and calculate each row separately. In this screen shot, you can see the A and B results, then A/B. Next, see the C calculations, and A/BC. At the bottom of the final column, the sum is shown. Use the Formula ResultIn other parts of your workbook, you can refer to cell A4 (DupIds), to create warning messages, or show a zero, instead of the expected results. For example, show a message with a formula like this:
Or, multiply by 1 (TRUE) or zero (FALSE) in other formulas, based on the number in the DupIDs cell.

COUNTIF and COUNTIFS WarningsThere are a few things to be careful with, when using the COUNTIF and COUNTIFS functions.
1) False Duplicates With COUNTIFBe careful when using COUNTIF, because it matches numbers, with text that looks like numbers, and that could result in false counts. For example, if you have a text entry  "00123"  it would be counted as a duplicate for the number  123. =COUNTIF($B$2:$B$10,B2))>1 If your data could contain entries like that, use SUMPRODUCT, instead of COUNTIF. =SUMPRODUCT(($B$2:$B$10=B2))>1 
2) Character Limit of 255COUNTIF and COUNTIFS can only check strings up to 255 characters. Here's a simple example to show the problem. This formula counts how many times an item appears in the Item column:
In row 5, there is a #VALUE! error, because the text in cell C1 is longer than 255 characters. Use a Different FunctionTo avoid the problem with the 255 character limit, use the SUMPRODUCT function, instead of COUNTIF or COUNTIFS. Here is the revised formula:
Here's how that SUMPRODUCT formula works:
Microsoft Workaround Does Not WorkOn Microsoft's COUNTIF page, it says you can work around the 255 character limit, by joining two long strings with the concatenate operator (&). Here's an example:
That suggestion does NOT work for me ! 
Get the COUNT Sample Files

More Function TutorialsCount Criteria in Other Column 
Last updated: February 24, 2023 3:42 PM