# Documentation/Calc Functions/COUNTIF

TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate

## Function name:

COUNTIF

## Category:

Statistical Analysis

## Summary:

Returns the number of cells that meet with certain criteria within a cell range.

## Syntax:

COUNTIF(**Range**; **Criteria**)

## Returns:

## Arguments:

**Range** is the range to which the criteria are to be applied.

**Criteria** indicates the criteria in the form of a number, an expression or a character string. These criteria determine which cells are counted.

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in **Tools > Options > LibreOffice Calc > Calculate**.

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".

## Additional details:

## Examples:

A1:A10 is a cell range containing the numbers 2000 to 2009. Cell B1 contains the number 2006. In cell B2, you enter a formula:

=COUNTIF(A1:A10;2006) - this returns 1.

=COUNTIF(A1:A10;B1) - this returns 1.

=COUNTIF(A1:A10;">=2006") - this returns 4.

=COUNTIF(A1:A10;"<"&B1) - when B1 contains 2006, this returns 6.

=COUNTIF(A1:A10;C2) where cell C2 contains the text >2006 counts the number of cells in the range A1:A10 which are >2006.

To count only negative numbers: =COUNTIF(A1:A10;"<0")