Use COUNTIF, one of the statistical functions, to count the number of cells that meet a criterion; for example, to count the number of times a particular city appears in a customer list.
In its simplest form, COUNTIF says:
- =COUNTIF(Where do you want to look?, What do you want to look for?)
For example:
- =COUNTIF(A2:A5,'London')
- =COUNTIF(A2:A5,A4)
Argument name | Description |
---|---|
range (required) | The group of cells you want to count. Range can contain numbers, arrays, a named range, or references that contain numbers. Blank and text values are ignored. Learn how to select ranges in a worksheet. |
criteria (required) | A number, expression, cell reference, or text string that determines which cells will be counted. For example, you can use a number like 32, a comparison like '>32', a cell like B4, or a word like 'apples'. COUNTIF uses only a single criteria. Use COUNTIFS if you want to use multiple criteria. |
Examples
To use these examples in Excel, copy the data in the table below, and paste it in cell A1 of a new worksheet.
Common Problems
Problem | What went wrong |
---|---|
Wrong value returned for long strings. | The COUNTIF function returns incorrect results when you use it to match strings longer than 255 characters. To match strings longer than 255 characters, use the CONCATENATE function or the concatenate operator &. For example, =COUNTIF(A2:A5,'long string'&'another long string'). |
No value returned when you expect a value. | Be sure to enclose the criteria argument in quotes. |
A COUNTIF formula receives a #VALUE! error when referring to another worksheet. | This error occurs when the formula that contains the function refers to cells or a range in a closed workbook and the cells are calculated. For this feature to work, the other workbook must be open. |
Best practices
Do this | Why |
---|---|
Be aware that COUNTIF ignores upper and lower case in text strings. | Criteria aren't case sensitive. In other words, the string 'apples' and the string 'APPLES' will match the same cells. |
Use wildcard characters. | Wildcard characters —the question mark (?) and asterisk (*)—can be used in criteria. A question mark matches any single character. An asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) in front of the character. For example, =COUNTIF(A2:A5,'apple?') will count all instances of 'apple' with a last letter that could vary. |
Make sure your data doesn't contain erroneous characters. | When counting text values, make sure the data doesn't contain leading spaces, trailing spaces, inconsistent use of straight and curly quotation marks, or nonprinting characters. In these cases, COUNTIF might return an unexpected value. Try using the CLEAN function or the TRIM function. |
For convenience, use named ranges | COUNTIF supports named ranges in a formula (such as =COUNTIF(fruit,'>=32')-COUNTIF(fruit,'>85'). The named range can be in the current worksheet, another worksheet in the same workbook, or from a different workbook. To reference from another workbook, that second workbook also must be open. |
Need more help?
You can always ask an expert in the Excel Tech Community, get support in the Answers community, or suggest a new feature or improvement on Excel User Voice.
See also
Count
Countif
Countifs
Sum
Sumif
Which Of The Following Is The Correct Argument(s)/syntax For The Countifs Function
Sumifs
1 Answer
WorksheetFunction
commands isn't great. It's a good idea to refer to the documentation for the related worksheet function. (ie., COUNTIFS
vs Application.WorksheetFunction.Countifs
)COUNTIFS
Syntax
COUNTIFS
function syntax has the following arguments:criteria1
(Required) The first range in which to evaluate the associated criteria.criteria1
(Required) The criteria in the form of a number, expression, cell reference, or text that define which cells will be counted.
For example, criteria can be expressed as32
,'>32'
,B4
,'apples'
, or'32'
.[criteria_range2, criteria2,] ..
(Optional) Additional ranges and their associated criteria.
Up to127
range/criteria pairs are allowed.
- Each additional range must have the same number of rows and columns as the
criteria_range1
argument. The ranges do not have to be adjacent to each other.
More Information:
- MSDN : WorksheetFunction.CountIfs Method (Excel)
- Office.com : COUNTIFS function (with video)
Not the answer you're looking for? Browse other questions tagged arraysexcelvbacountif or ask your own question.
Function Syntax
Number of Arguments
Types of Data in Arguments
- the actual data being summed - the Number1 argument in the image above
- an individual cell reference to the location of the number data in the worksheet - the Number2 argument
- an array or range of cell references - the Number3 argument
- text data
- other functions
Nesting Functions
Finding a Function's Arguments
- Open the function's dialog box in Excel
- Tooltip windows in Excel and Google Sheets
Excel Function Dialog Boxes
- finding and clicking on a function's name under the Formulatab of the ribbon;
- clicking on theInsert Function option located next to the formula bar, as indicated in the image above.
Tooltips: Typing a Function's Name
- Click on a cell,
- Enter the equal sign - to notify the program that a formula is being entered
- Enter the function's name - as you type, the names of all functions starting with that letter appear in a tooltip below the active cell;
- Enter an open parenthesis - the specified function and its arguments are listed in the tooltip.
The COUNTIFS function applies criteria to cells across multiple ranges and counts the number of times all criteria are met.
This video is part of a training course called Advanced IF functions.
Syntax
COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)
The COUNTIFS function syntax has the following arguments: