Google sheets - How to use countif to count the number of matching cells in a range

In Google sheets you can use countif to conditionally count cells in a range. For example the following formula will count numbers larger than zero in range A3:A8:

=COUNTIF(A3:A8, ">0")

It can be seen on this sheet, or in the image below:

google-sheets-simple-count-if

You can use all the usual comparison operators like =, >, <, >= and <=.

Matching strings

countif can also be used with strings, if we wish to count the number of strings with the content Pending in the range D3:D8 we can use the following formula:

=COUNTIF(D3:D8, "=Pending")

It can be seen on this sheet, or in the image below:

google-sheets-simple-count-if-strings

You can use ? as a wildcard character for any character. You can use * to match continuous characters, such as *ing will match both Pending and Processing. ~ can be used to escape ? and * such as ~? and ~*, should they be a part of the string.

Matching multiple criterias

The countif function can only perform matching with a single condition, a simple way to circumvent this is to add multiple countifs together to "match multiple conditions". If we want to count both Pending and Processed from the range H3:H8, we can simply add the two countifs together:

=COUNTIF(H3:H8, "=Pending")+COUNTIF(H3:H8, "=Processed")

It can be seen on this sheet, or in the image below:

google-sheets-simple-count-if-multiple-strings


That is all

I hope you found this helpful, feel free to leave a comment down below with your thoughts, or if I missed something useful for others!

If you would rather sum the rows, you can check out my post on sumif!