COUNTIF function - Microsoft Support (2024)

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 function - Microsoft Support (1)

COUNTIF(range, criteria)

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.

Data

Data

apples

32

oranges

54

peaches

75

apples

86

Formula

Description

=COUNTIF(A2:A5,"apples")

Counts the number of cells with apples in cells A2 through A5. The result is 2.

=COUNTIF(A2:A5,A4)

Counts the number of cells with peaches (the value in A4) in cells A2 through A5. The result is 1.

=COUNTIF(A2:A5,A2)+COUNTIF(A2:A5,A3)

Counts the number of apples (the value in A2), and oranges (the value in A3) in cells A2 through A5. The result is 3. This formula uses COUNTIF twice to specify multiple criteria, one criteria per expression. You could also use the COUNTIFS function.

=COUNTIF(B2:B5,">55")

Counts the number of cells with a value greater than 55 in cells B2 through B5. The result is 2.

=COUNTIF(B2:B5,"<>"&B4)

Counts the number of cells with a value not equal to 75 in cells B2 through B5. The ampersand (&) merges the comparison operator for not equal to (<>) and the value in B4 to read =COUNTIF(B2:B5,"<>75"). The result is 3.

=COUNTIF(B2:B5,">=32")-COUNTIF(B2:B5,"<=85")

Counts the number of cells with a value greater than (>) or equal to (=) 32 and less than (<) or equal to (=) 85 in cells B2 through B5. The result is 1.

=COUNTIF(A2:A5,"*")

Counts the number of cells containing any text in cells A2 through A5. The asterisk (*) is used as the wildcard character to match any character. The result is 4.

=COUNTIF(A2:A5,"?????es")

Counts the number of cells that have exactly 7 characters, and end with the letters "es" in cells A2 through A5. The question mark (?) is used as the wildcard character to match individual characters. The result is 2.

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.

Note:The COUNTIF function will not count cells based on cell background or font color. However, Excel supports User-Defined Functions (UDFs) using the Microsoft Visual Basic for Applications (VBA) operations on cells based on background or font color. Here is an example of how you can Count the number of cells with specific cell color by using VBA.

Need more help?

You can always ask an expert in the Excel Tech Communityor get support inCommunities.

See also

COUNTIFS function

IF function

COUNTA function

Overview of formulas in Excel

IFS function

SUMIF function

COUNTIF function - Microsoft Support (2024)

FAQs

What is the Microsoft Excel formula Countif? ›

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

Why is Countif function not working in Excel? ›

Check Syntax:

This is the most common reason why COUNTIF doesn't work. Make sure that you have entered the function correctly, including the parentheses and quotation marks.

How do I use Countif in Excel for text? ›

In the empty cell, you can input the formula to count cells with text. The Excel formula for this function is "=COUNTIF (range, criteria)" without quotation marks. In this formula, the range is the cells you want to include in your count and the criteria is text.

How to use countif function in Excel with multiple criteria? ›

Step 1: Document the criteria or conditions you wish to test for. Step 2: Type “=countifs(“ and select the range you want to test the first criteria on. Step 3: Input the test for the criteria. Step 4: Select the second range you want to test (it can be the same range again, or a new one).

What is the difference between Countif and Countifs? ›

The difference is that COUNTIF is designed for counting cells with a single condition in one range, whereas COUNTIFS can evaluate different criteria in the same or in different ranges.

How do I use Countif spreadsheet? ›

=COUNTIF(range, criterion)

The cell range can have text strings or numbers. The criteria can use comparison or logical operators if the range of cells contains numbers, including: > greater than. < less than.

How do I get Countifs to work? ›

How to Use COUNTIFS Function in Excel?
  1. Open the COUNTIFS formula.
  2. Select column A (region) as the “criteria_range1.” Alternatively, you can select column B (product).
  3. Select the “criteria1” for the range A2:A13. ...
  4. Select column B (product) as the “criteria_range2.”
  5. Select the “criteria2” for the range B2:B13.
Dec 27, 2023

Why is countifs not counting correctly? ›

Try removing the space between the quotes. You are counting all cells with 1 space in the cell. Blanks are counted with the quotes together. When counting blanks though, its also good to use a COUNTIFS and compare the blank off another column that always has a value.

What are the disadvantages of Countif in Excel? ›

Limitations of COUNTIF
  • It is not designed to handle more than one condition at a time. ...
  • COUNTIF is not case-sensitive. ...
  • The COUNTIF formula in Excel might give wrong results if you try to match strings that are longer than 255 characters.
  • It doesn't count cells based on cell background or font color.
Mar 5, 2024

How to count if there is anything in a cell? ›

Ways to count cells in a range of data
  1. COUNTA: To count cells that are not empty.
  2. COUNT: To count cells that contain numbers.
  3. COUNTBLANK: To count cells that are blank.
  4. COUNTIF: To count cells that meets a specified criteria. Tip: To enter more than one criterion, use the COUNTIFS function instead.

How to count in Excel with condition? ›

To count numbers or dates that meet a single condition (such as equal to, greater than, less than, greater than or equal to, or less than or equal to), use the COUNTIF function.

How to count a certain value in Excel? ›

If you want to count logical values, text, or error values, use the COUNTA function. If you want to count only numbers that meet certain criteria, use the COUNTIF function or the COUNTIFS function.

What are the logical operators for Countif? ›

Criteria
Logical OperatorsConditionTRUE Condition Examples
>Greater than3>2 (three is greater than two)
<>Not equal to3<>2 (three is not equal to two)
<=Less than or equal to3<=3 (three is less than or equal to three)
>=Greater than or equal to3>=3 (three is greater than or equal to three)
2 more rows

How do you use Countifs with range criteria? ›

The Excel COUNTIF function returns the count of cells in a range that meet a single condition. The generic syntax is COUNTIF(range, criteria), where "range" contains the cells to count, and "criteria" is a condition that must be true for a cell to be counted. COUNTIF can be used to count cells...

How to apply count formula in Excel? ›

Use the COUNT function to get the number of entries in a number field that is in a range or array of numbers. For example, you can enter the following formula to count the numbers in the range A1:A20: =COUNT(A1:A20). In this example, if five of the cells in the range contain numbers, the result is 5.

What does the formula countif A1 A10 10 do in Excel? ›

This will count the number of cells in the range A1 to A10 with values greater than 10.

How do you count how many of each value in Excel? ›

Count how often a single value occurs by using the COUNTIF function. Use the COUNTIF function to count how many times a particular value appears in a range of cells.

References

Top Articles
My job in F1: Sky F1 lead commentator David Croft
Coulthard: Schwindende Red-Bull-Dominanz schon in Bahrain ersichtlich
Ucsf Ilab
Fiat 600e: Dolce Vita auf elektrisch
Formulaire 3CEp - COPRAUDIT
Revolve 360 Extend Manual
Trivago Manhattan
Craigslist Free Stuff Merced Ca
Nancy Caroline (Kindley) Walker - Goodwin Funeral Home
Mashle: Magic And Muscles Gogoanime
Eso Mud Ball Miscreant
Equipment Hypixel Skyblock
Cristiano Ronaldo's Jersey Number: The Story Behind His No. 7 Shirt | Football News
Metro By T Mobile Sign In
Hailie Deegan News, Rumors, & NASCAR Updates
Ravens 24X7 Forum
Telegram X (Android)
Irissangel
Craigslist Albany Oregon Free Stuff
Paperless Pay.talx/Nestle
Claims Adjuster: Definition, Job Duties, How To Become One
Brianna Aerial Forum
Cdn Bustednewspaper
April 7 Final Jeopardy
Express Pay Cspire
Battlenet We Couldn't Verify Your Account With That Information
Adopting Remote UniFi Devices with Windows Server DHCP – itramblings
Wdl Nursing Abbreviation
Money Rose Stencil
Neos Urgent Care Springfield Ma
Fastest Lovakengj Favour
Abby's Caribbean Cafe
Speer Funeral Home Aledo Il Obituaries
In Branch Chase Atm Near Me
619-354-3954
Managementassistent directie Wonen
Osrs Desert Heat
Uw Oshkosh Wrestling
Fitbod Lifetime
How Much Is Felipe Valls Worth
Csi Trigonometry Answer Key
Nike.kronos/Wfm/Login
Mosley Lane Candles
4215 Tapper Rd Norton Oh 44203
Dollar General Penny List July 18 2023
Varsity Competition Results 2022
Backrooms Level 478
XY6020L 6-70V CNC einstellbares stabilisiertes Spannungsnetzteil Konstantspannung Konstantstrom 20A/1200W Buck-Modul Bewertungen
Baja Boats For Sale On Craigslist
South Florida residents must earn more than $100,000 to avoid being 'rent burdened'
Funny Roblox Id Codes 2023
The Ultimate Guide to Newquay Surf - Surf Atlas
Latest Posts
Article information

Author: Terence Hammes MD

Last Updated:

Views: 5614

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Terence Hammes MD

Birthday: 1992-04-11

Address: Suite 408 9446 Mercy Mews, West Roxie, CT 04904

Phone: +50312511349175

Job: Product Consulting Liaison

Hobby: Jogging, Motor sports, Nordic skating, Jigsaw puzzles, Bird watching, Nordic skating, Sculpting

Introduction: My name is Terence Hammes MD, I am a inexpensive, energetic, jolly, faithful, cheerful, proud, rich person who loves writing and wants to share my knowledge and understanding with you.