This article describes the formula syntax and usage of the COUNTIF function (function: A prewritten formula that takes a value or values, performs an operation, and returns a value or values. Use functions to simplify and shorten formulas on a worksheet, especially those that perform lengthy or complex calculations.) in Microsoft Excel.
The COUNTIF function counts the number of cells within a range that meet a single criterion that you specify. For example, you can count all the cells that start with a certain letter, or you can count all the cells that contain a number that is larger or smaller than a number you specify. For example, suppose you have a worksheet that contains a list of tasks in column A, and the first name of the person assigned to each task in column B. You can use the COUNTIF function to count how many times a person's name appears in column B and, in that way, determine how many tasks are assigned to that person. For example:
Note To count cells based on multiple criteria, see COUNTIFS function.
The COUNTIF function syntax has the following arguments (argument: A value that provides information to an action, an event, a method, a property, a function, or a procedure.):
- range Required. One or more cells to count, including numbers or names, arrays, or references that contain numbers. Blank and text values are ignored.
- criteria Required. A number, expression, cell reference, or text string that defines which cells will be counted. For example, criteria can be expressed as 32, ">32", B4, "apples", or "32".
- You can use the wildcard characters — the question mark (?) and the asterisk (*) — in criteria. A question mark matches any single character, and an asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) before the character.
- Criteria are case insensitive; for example, the string "apples" and the string "APPLES" will match the same cells.
- The COUNTIF function returns incorrect results when you use it to match strings longer than 255 characters to the string #VALUE!.
The workbook below shows examples of this function. Inspect them, change existing formulas, or enter your own formulas to learn how the function works.
To work more in-depth with the example data in Excel, download the embedded workbook to your computer, and then open it in Excel.