Which function counts the number of cells within a range that meet the criteria?

See 7 ways to count in Excel. Examples and video tutorials show how to count Excel cells with numbers, text, blanks, or cells that contain specific words or other criteria

Which function counts the number of cells within a range that meet the criteria?

Overview: 7 Ways to Count in Excel

To see a quick overview of 7 ways to get a total count of cells in Excel, watch this short video. Or, watch the Slide Show: 7 Ways to Count, further down on this page.

Get the 7 Ways to Count sample workbook, so you can follow along with the video.

Count Numbers, All Data, or Blank Cells

This 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 Cells with Numbers -- COUNT

The COUNT function will count cells that contain numbers.

Its syntax has one required argument, and up to 255 additional items, that are optional:

  • =COUNT(value1, [value2],...])

COUNT Function Notes

  • COUNT function arguments can be cell references, or values typed into the COUNT formula.
  • Because dates are stored as numbers in Excel, the COUNT function will count any cells that contain valid dates.
  • You can refer to cell ranges that include non-numeric values, but only the cells with numbers will be counted

COUNT Function Example

In the screen shot below, there's a variety of data entered in column A:

  • A2: number
  • A3: text
  • A4: date
  • A5: blank cell

The following COUNT formula is entered in cell A7, using one value argument - a reference to a range of cells:

 =COUNT(A2:A5)  

Excel counts the number (A2) and the date (A4), so the formula result, in cell A7, is a count of 2.

Note: The text value and the blank cell are not counted.

COUNT Function Results

To verify the count, I used the COUNT function in cells B2:B7, to count each item in column A.

  • Here is the formula in cell B2: =COUNT(A2)
  • The formula was copied down to cell B5
  • In each row, the formula result is 1 or zero, and the total for column B is 2 -- the same result as the COUNT formula in cell A7

Verify with ISNUMBER

For a different verification method, I use the ISNUMBER function in column C, to check each value in column A.

  • Here is the formula in cell C2: =ISNUMBER(A2)
  • The formula was copied down to cell C5
  • In each row, the formula result is TRUE or FALSE
  • The number of TRUE results is 2 -- the same result as the COUNT formula in cell A7

Which function counts the number of cells within a range that meet the criteria?

Count Cells with Data -- COUNTA

The COUNTA function will count cells that are not empty. (See note on blank cells below)

Its syntax is:
    =COUNTA(value1, value2,...value30).
The arguments (e.g. value1) can be cell references, or values typed into the formula. The following example uses one argument -- a reference to cells A1:A5.

  1. Enter the sample data on your worksheet
  2. In cell A7, enter a COUNTA formula, to count the numbers in column A:   =COUNTA(A1:A5)  
  3. Which function counts the number of cells within a range that meet the criteria?

  4. Press the Enter key, to complete the formula.
  5. The result will be 4, the number of cells that contain data.

Count Blank Cells -- COUNTBLANK

The COUNTBLANK function will count cells that are empty. (See note on blank cells below)

Its syntax is:
    =COUNTBLANK(range).
The following example uses a reference to cells A1:A5.

  1. Enter the sample data on your worksheet
  2. In cell A7, enter a COUNTBLANK formula, to count the numbers in column A:   =COUNTBLANK(A1:A5)  
  3. Which function counts the number of cells within a range that meet the criteria?

  4. Press the Enter key, to complete the formula.
  5. The result will be 1, the number of empty cells.

Cells That Look Blank

Both COUNTA and COUNTBLANK will count cells with formulas that look empty, if the formula result is an empty string {""). The empty string is treated as text, and counted.

For example, =IF(B2="","",B2).

Both COUNTA and COUNTBLANK will also count cells which had formulas that returned an empty string, but then were converted to values, by copying and pasting as values.

  • NOTE: You can see apostrophes in those "non-blank" converted cells, if you add a check mark to Excel Options, Advanced, Lotus Compatibility, "Transition navigation keys." 

To fix cells that look blank, but are being counted, see my Contextures blog: Fix Blank Excel Cells Copied From Database  ▲TOP

Count cells that match one criterion

This 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 instructions are below the video: Match criterion exactly and Match criterion in a string

Match one criterion exactly -- COUNTIF

In Excel, count cells that meet a specific criterion. In this example only the Pen orders will be counted.

  1. Select the cell in which you want to see the count (cell A12 in this example)
  2. Type an equal sign (=) to start the formula
  3. Type:   COUNTIF(
  4. Select the cells that contain the values to check for the criterion. In this example, cells A1:A10 will be checked
  5. Type a comma, to separate the arguments
  6. Type the criterion. In this example, you're checking for text, so type the word in double quotes:   "Pen"
    Note: upper and lower case are treated equally
  7. Type a closing bracket
    The completed formula is: =COUNTIF(A1:A10,"Pen")
  8. Which function counts the number of cells within a range that meet the criteria?

  9. Press the Enter key to complete the entry
  10. The result will be 4, the number of cells that contain "Pen"  ▲TOP

Match criterion in a string

In Excel, count cells that contain a criterion as part of the cell's contents. In this example all Pen, Gel Pen, and Pencil orders will be counted, because they contain the string "pen".

  1. Select the cell in which you want to see the count (cell A12 in this example)
  2. Type an equal sign (=) to start the formula
  3. Type:   COUNTIF(
  4. Select the cells that contain the values to check for the criterion. In this example, cells A1:A10 will be checked
  5. Type a comma, to separate the arguments
  6. Type the criterion. In this example, you're checking for text, so type the word in double quotes, with one or more asterisk (*) wildcard characters:   "*Pen*"
    Note: upper and lower case are treated equally
  7. Type a closing bracket
    The completed formula is: =COUNTIF(A1:A10,"*Pen*")
  8. Which function counts the number of cells within a range that meet the criteria?

  9. Press the Enter key to complete the entry
  10. The result will be 6, the number of cells that contain the string, "Pen"  ▲TOP

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:
    =COUNTIF(A1:A10,"*" & B12 & "*")
if cell B12 contained the text — pen.

COUNTIF and COUNTIFS Warnings

There are a few things to be careful with, when using the COUNTIF and COUNTIFS functions.

False Duplicates With COUNTIF

Be 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

Which function counts the number of cells within a range that meet the criteria?

Character Limit of 255

COUNTIF 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.

Which function counts the number of cells within a range that meet the criteria?

Use a Different Function

To avoid the problem with the 255 character limit, use the SUMPRODUCT function, instead of COUNTIF or COUNTIFS. Here is the revised formula:

  • =SUMPRODUCT(--([Item]=[@Item]))

Here's how that SUMPRODUCT formula works:

  • Checks each row [Item] to see if it's equal to the entry in the current row [@Item]
  • The result is TRUE or FALSE for each row (highlighted in the screen shot below -- I pressed F9 to evaluate that section of the formula)
  • The two minus signs (double unary) change TRUE to 1 and FALSE to 0
  • SUMPRODUCT adds up the 1s and 0s.

Which function counts the number of cells within a range that meet the criteria?

Microsoft Workaround Does Not Work

On 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:

  • =COUNTIF(A2:A5,"long string"&"another long string")

That suggestion does NOT work for me !

Count Numbers in Numbers

The 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.

Which function counts the number of cells within a range that meet the criteria?

Although 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).

  • C2: =COUNTIF(A2,"*1*")
  • D2: =--ISNUMBER(FIND(1,A2))
  • E2: =--ISNUMBER(SEARCH(1,A2))

The FIND and SEARCH formulas found all 4 items that contain a "1". The COUNTIF formula only found 3 items.

Which function counts the number of cells within a range that meet the criteria?

Instead of checking each row individually, use the SUMPRODUCT function with FIND or SEARCH, to get the total count for the list.

  • Use FIND to count numbers, or case-sensitive letters
  • Use SEARCH to count numbers, or upper and lower case letters (not case-sensitive)

Example 1: Numbers

In this example, the formulas give a count of cells that contain a 1. The result is 4 in both cases.

  • A9:    =SUMPRODUCT(--ISNUMBER(FIND(1,$A$2:$A$7)))
  • A10:  =SUMPRODUCT(--ISNUMBER(SEARCH(1,$A$2:$A$7)))

Which function counts the number of cells within a range that meet the criteria?

Example 2: Letters

In the next example, the formulas give a count of cells that contain "a". FIND only counts the lower-case "a" (1), and SEARCH counts both the upper-case "A", and lower-case "a" (2).

  • A9:   =SUMPRODUCT(--ISNUMBER(FIND("a",$A$2:$A$7)))
  • A10: =SUMPRODUCT(--ISNUMBER(SEARCH("a",$A$2:$A$7)))

Which function counts the number of cells within a range that meet the criteria?

Count Cells "Less Than" or "Greater Than"

In 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 to

You 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.

  1. Select the cell in which you want to see the count (cell A12 in this example)
  2. Type an equal sign (=) to start the formula
  3. Type:   COUNTIF(
  4. Select the cells that contain the values to check for the criterion. In this example, cells B1:B10 will be checked
  5. Type a comma, to separate the arguments
  6. Type the criterion. In this example, you're checking for rows where the quantity is greater than or equal to 10. The >= operator is used before the number, and the entire criterion is enclosed in double quotes: ">=10"
    Note: Even though this is a numerical criterion, it must enclosed in double quote marks.
  7. Type a closing bracket
  8. The completed formula is:
              =COUNTIF(B1:B10,">=10")
  9. Press the Enter key to complete the entry

    Which function counts the number of cells within a range that meet the criteria?

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:
    =COUNTIF(B1:B10,">=" & B12)
if cell B12 contained the number — 10. 

Or, you could use a function as part of the criterion. For example:
    =COUNTIF(A1:A10,"<"&TODAY())   ▲TOP

Count Cells Between 5 and 10

You can combine COUNTIF formulas, to count rows that are within a range of values. In this example, the formula will count rows where the quantity is between 5 and 10 (inclusive).

  1. Select the cell in which you want to see the count (cell A12 in this example)
  2. Type a formula to count rows greater than or equal to 5:
              =COUNTIF(B1:B10,">=5")
  3. Type a minus sign
  4. Type a formula to count rows greater than 10:
              COUNTIF(B1:B10,">10")
  5. The completed formula is:
    =COUNTIF(B1:B10,">=5")-COUNTIF(B1:B10,">10")
  6. Press the Enter key to complete the entry

    Which function counts the number of cells within a range that meet the criteria?

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:
    =COUNTIF(B1:B10,">=" & B12) -
            COUNTIF(B1:B10,">" & C12)
if cell B12 contained the number — 5 and cell C12 contained the number — 10.   ▲TOP

Change Operator for COUNTIF Function

Instead 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 Operators

To create a drop down list operators:

  1. On a different sheet in the workbook, type a list of operators in a column.
  2. Select the cells in the list, and name that list as OpList.

    Which function counts the number of cells within a range that meet the criteria?

  3. On the main sheet, select the cell where you want the drop down list -- cell E6 in this example
  4. Use the data validation command to create the drop down list, based on the named range -- OpList

Which function counts the number of cells within a range that meet the criteria?

Use the Drop Down List

Change 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.

Which function counts the number of cells within a range that meet the criteria?

Count cells that match multiple criteria

This 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 Cells that Match multiple criteria

In Excel 2007 and later versions, you can use the COUNTIFS function to count rows that meet two or more criteria. In this example only the rows where the item is "Pen" and the quantity is greater than or equal to ten will be counted.

  1. Select the cell in which you want to see the total
  2. Type an equal sign (=) to start the formula
  3. Type:   COUNTIFS(
  4. Select the cells that contain the values to check for the first criterion. In this example, cells A2:A10 will be checked
  5. Type a comma, and the first criterion:   "Pen"
    Note: Because this is a text criterion, it is enclosed in double quote marks.
  6. To start the next set of criteria, type a comma
  7. Select the cells that contain the values to check for the second criterion. In this example, cells B2:B10 will be checked
  8. Type a comma, and the second criterion:  ">=10"
    Note: Because this criterion includes operators, it is enclosed in double quote marks. To count rows where the quantity is equal to 10, only the number 10 would be required.
  9. Finish with a closing bracket: )
  10. The completed formula is shown below.
  11. Press the Enter key to complete the entry

Which function counts the number of cells within a range that meet the criteria?

Note: Instead of typing the criterion in a formula, you can refer to a cell, as shown in the second formula below. If using operators, enclose them in double quote marks.

Use typed criteria:

=COUNTIFS(A2:A10,"Pen",B2:B10,">=10")

=COUNTIFS(A2:A10,D3,B2:B10,">=" & E3)

Count cells that match multiple criteria -- SUMPRODUCT

In 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.

  1. Select the cell in which you want to see the total
  2. Type an equal sign (=) to start the formula
  3. Type:   SUMPRODUCT(--(
  4. Select the cells that contain the values to check for the first criterion. In this example, cells A2:A10 will be checked
  5. Type the first criterion:   ="Pen"
    Note: Because this is a text criterion, it is enclosed in double quote marks.
  6. Type ),--(
  7. Select the cells that contain the values to check for the second criterion. In this example, cells B2:B10 will be checked
  8. Type the second criterion:   >=10
    Note: Because this is a numerical criterion, it isn't enclosed in double quote marks.
  9. Finish with closing brackets: ))
  10. The completed formula is shown below.
  11. Press the Enter key to complete the entry

Which function counts the number of cells within a range that meet the criteria?

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))

Count All Dates in Specific Month and Year

In this example, there is a date in cell A2, and the order list has dates in cell A5:A26. The following SUMPRODUCT function is in cell D2, and it counts all the dates that have the same month and year as the date in cell A2.

=SUMPRODUCT((MONTH(A5:A26)=MONTH(A2))*(YEAR(A5:A26)=YEAR(A2)))

  • The MONTH function returns the month number for each cell, and compares that to the month number for the date in cell A2.
  • The YEAR function returns the year number for each cell, and compares that to the year number for the date in cell A2.
  • Only the rows where both the month and year match cell A2 are counted.

Which function counts the number of cells within a range that meet the criteria?

Count Duplicated Items in List

In 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.

Which function counts the number of cells within a range that meet the criteria?

The formula shown below will count how many unique values have been duplicated.

  • In this example, the formula result should be 2 -- there are 2 unique values that have been duplicated - 2 and 3.
  • The formula will NOT tell us that 4 rows contain duplicated ID numbers.

Formula to Count Duplicated Items

Duplicate 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]<>"") /
    COUNTIF(tblIDs[ID],tblIDs[ID]&"") -
    (COUNTIF(tblIDs[ID],tblIDs[ID])=1))

Which function counts the number of cells within a range that meet the criteria?

NOTE: To simply highlight duplicate values in a column, use Conditional Formatting.

How It Works

The SUMPRODUCT formula contains 3 formulas:

  • A: (tblIDs[ID]<>"") - Check if the cell is NOT empty - TRUE (1) or FALSE (0)
  • B: COUNTIF(tblIDs[ID],tblIDs[ID]&"") - How many times does the ID appear in the column
  • C: (COUNTIF(tblIDs[ID],tblIDs[ID])=1) - Number (B) is equal to one - TRUE (1) or FALSE (0)

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 Bar

In 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.

Which function counts the number of cells within a range that meet the criteria?

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.

Which function counts the number of cells within a range that meet the criteria?

Next, calculate A/B - C, to see these results. TRUE is 1 and FALSE is zero, so 1-1 equals zero, and 0.5 - 0 equals 0.5:

Which function counts the number of cells within a range that meet the criteria?

Finally, the SUMPRODUCT function gives the sum of those numbers, with the result of 2.

Worksheet Formulas

You 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/B-C. At the bottom of the final column, the sum is shown.

Which function counts the number of cells within a range that meet the criteria?

Use the Formula Result

In 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:

  • =IF(DupIDs>0,"Before continuing, remove duplicate IDs.","")

Or, multiply by 1 (TRUE) or zero (FALSE) in other formulas, based on the number in the DupIDs cell.

  • =COUNT(tblIDs[ID])*--(DupIDs=0)

Which function counts the number of cells within a range that meet the criteria?

Count Rows in a Filtered List

After you filter the rows in a list, you can use functions to count only the visible rows.

Count Rows in a Filtered List With SUBTOTAL

After you filter the rows in a list, you can use the SUBTOTAL function to count the visible rows.

  1. Apply an AutoFilter to the table. There are instructions here -- AutoFilter Basics
  2. Filter at least one of the columns in the table. In this example, the first column has been filtered for Binders.
  3. Select the cell immediately below the column you want to sum.
  4. Click the AutoSum button on the Excel's Standard toolbar.
    • If you want the SUBTOTAL function in a cell other than the one directly below the filtered list, you can type the formula, instead of using the AutoSum button.
  5. A SUBTOTAL formula will be automatically inserted, totalling the visible cells in the column
    • The first argument in the SUBTOTAL function is a function number, that specifies how the numbers should be calculated. The default is 9, which tells Excel to SUM the numbers.
    • Other function numbers can be used, such as 1 for AVERAGE, and 3 for COUNTA. Look in Excel's Help for a complete list.
  6. To Count all the non-empty cells in column D, use a 3 as the first argument:
    =SUBTOTAL(3,D2:D10)
  7. Press the Enter key to complete the formula entry.

    Which function counts the number of cells within a range that meet the criteria?

  8. Note: To subtotal rows which have been either manually hidden or filtered, use 103 as the function number, instead of 3:
        =SUBTOTAL(103,D2:D10)
      ▲TOP

Count Rows in Filtered List With AGGREGATE

After 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.

  1. Apply an AutoFilter to the table. There are instructions here -- AutoFilter Basics
  2. Filter at least one of the columns in the table. In this example, the first column has been filtered for Binders.
  3. Select the cell in which you want to see the total -- cell B1 in this example
  4. To start the formula, type:   =AGGREGATE(
  5. In the list of function numbers, double-click on 3-COUNTA, then type a comma
  6. In the list of option numbers, double-click on 3 - Ignore hidden rows, error values, nested SUBTOTAL and AGGREGATE functions, then type a comma
  7. Select the cells that contain the values to check for the first criterion. In this example, the Total column in the table is selected.
  8. Type a closing bracket, then press the Enter key to complete the formula entry.
    =AGGREGATE(3,3,Table1[Total])

The two visible numbers are counted, and the error in cell D9 is ignored.

Which function counts the number of cells within a range that meet the criteria?

Count Specific Items in a Filtered List

Laurent 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):
            https://web.archive.org/web/20100110043824/ https://j-walk.com/ss/excel/eee/eee001.txt

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.

Which function counts the number of cells within a range that meet the criteria?

  1. From the drop down list in cell D1, select Custom.
  2. Filter for rows greater than 100.
  3. In cell A12, type: Pen
  4. In cell B12, enter the following formula:

=SUMPRODUCT(SUBTOTAL(3,OFFSET(A1:A10,ROW(A1:A10)
              -MIN(ROW(A1:A10)),,1)), --(A1:A10=A12))

  1. Press the Enter key to complete the formula entry.   ▲TOP

Count Unique Items in a Filtered List

In 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 for the Central region, and unique items in column D are counted.

Is a function that counts the number of cells within a range that meet a single criterion that your specify?

Excel COUNTIF function is used for counting cells within a specified range that meet a certain criterion, or condition. For example, you can write a COUNTIF formula to find out how many cells in your worksheet contain a number greater than or less than the number you specify.

Which function counts the number of cells within a range of cells?

The COUNT function counts the number of cells that contain numbers, and counts numbers within the list of arguments. Use the COUNT function to get the number of entries in a number field that is in a range or array of numbers.

Which function would you use to count the number of cells in a range that are not empty a Counta B count c counter D Countb?

The COUNTA function in Excel counts cells containing any value, i.e. cells that are not empty. The syntax of the Excel COUNTA function is akin to that of COUNT: COUNTA(value1, [value2], …)

What function counts the number of cells within a range that meet multiple criteria?

The COUNTIFS function applies criteria to cells across multiple ranges and counts the number of times all criteria are met.