Count if true excel

Excel for Microsoft 365 Excel 2021 Excel 2019 Excel 2016 Excel 2013 Excel 2010 Excel 2007 More…Less

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. To count numbers or dates that fall within a range (such as greater than 9000 and at the same time less than 22500), you can use the COUNTIFS function. Alternately, you can use SUMPRODUCT too.

Example

Note: You’ll need to adjust these cell formula references outlined here based on where and how you copy these examples into the Excel sheet.

1

A

B

2

Salesperson

Invoice

3

Buchanan

15,000

4

Buchanan

9,000

5

Suyama

8,000

6

Suyma

20,000

7

Buchanan

5,000

8

Dodsworth

22,500

9

Formula

Description (Result)

10

=COUNTIF(B2:B7,»>9000″)

The COUNTIF function counts the number of cells in the range B2:B7 that contain numbers greater than 9000 (4)

11

=COUNTIF(B2:B7,»<=9000″)

The COUNTIF function counts the number of cells in the range B2:B7 that contain numbers less than 9000 (4)

12

=COUNTIFS(B2:B7,»>=9000″,B2:B7,»<=22500″)

The COUNTIFS function (available in Excel 2007 and later) counts the number of cells in the range B2:B7 greater than or equal to 9000 and are less than or equal to 22500 (4)

13

=SUMPRODUCT((B2:B7>=9000)*(B2:B7<=22500))

The SUMPRODUCT function counts the number of cells in the range B2:B7 that contain numbers greater than or equal to 9000 and less than or equal to 22500 (4). You can use this function in Excel 2003 and earlier, where COUNTIFS is not available.

14

Date

15

3/11/2011

16

1/1/2010

17

12/31/2010

18

6/30/2010

19

Formula

Description (Result)

20

=COUNTIF(B14:B17,»>3/1/2010″)

Counts the number of cells in the range B14:B17 with a data greater than 3/1/2010 (3)

21

=COUNTIF(B14:B17,»12/31/2010″)

Counts the number of cells in the range B14:B17 equal to 12/31/2010 (1). The equal sign is not needed in the criteria, so it is not included here (the formula will work with an equal sign if you do include it («=12/31/2010»).

22

=COUNTIFS(B14:B17,»>=1/1/2010″,B14:B17,»<=12/31/2010″)

Counts the number of cells in the range B14:B17 that are between (inclusive) 1/1/2010 and 12/31/2010 (3).

23

=SUMPRODUCT((B14:B17>=DATEVALUE(«1/1/2010»))*(B14:B17<=DATEVALUE(«12/31/2010»)))

Counts the number of cells in the range B14:B17 that are between (inclusive) 1/1/2010 and 12/31/2010 (3). This example serves as a substitute for the COUNTIFS function that was introduced in Excel 2007. The DATEVALUE function converts the dates to a numeric value, which the SUMPRODUCT function can then work with.

Need more help?

Count the number of cells that contain TRUE, FALSE, or one of the two. This lets you count the logical values in a range in Excel.

Sections:

Count Cells that Contain TRUE

Count Cells that Contain FALSE

Count Cells that Contain TRUE or FALSE

Notes

Count Cells that Contain TRUE

=COUNTIF(A1:A5,TRUE)

A1:A5 is the range in which to count; change it to fit your data.

TRUE is the value that we want to count. Note that this does not require quotation marks around it; TRUE and FALSE are special elements in Excel.

a3ce3e1ddc264d03141c10158e61ee4a.png

Result:

c01d0884776f6ad2cc309211a2b82837.png

Count Cells that Contain FALSE

=COUNTIF(A1:A5,FALSE)

A1:A5 is the range in which to count; change it to fit your data.

FALSE is the value that we want to count. Note that this does not require quotation marks around it; TRUE and FALSE are special elements in Excel.

bb9bc8294b9e3575720074ccb1cb9109.png

Result:

c2ee13c58f8a3533d17c463e4c3fc789.png

Count Cells that Contain TRUE or FALSE

Essentially, we now combine the last two examples into one formula.

=COUNTIF(A1:A5,TRUE)+COUNTIF(A1:A5,FALSE)

d390469c176b548c4cbc5c05936ce602.png

Result:

286d309c95ffcd970fda86ab6e528994.png

Notes

This is pretty basic COUNTIF stuff combined with the logical values of TRUE and FALSE and, as you can see, it’s not complex. The one thing to remember is that you do not put quotation marks around TRUE and FALSE; now, you can get away with doing that, but it’s not necessary.

Download the sample file for this tutorial to work with these examples in Excel.

Similar Content on TeachExcel

Determine if Cells Contain a Specific Value in Excel

Tutorial: Find if a cell or range of cells contains a specific value in Excel. This method can be us…

Multiply by True and False in Excel

Tutorial:
You can multiply numbers by TRUE and FALSE in Excel. This effectively allows you to elimi…

Convert Numbers into True and False in Excel

Tutorial: How to convert numbers into the TRUE and FALSE Boolean values in Excel. This is very impor…

NOT Function — Change False to True and True to False in Excel

Tutorial:
Change True to False and False to True with this simple function in Excel.
To do this, we…

Check if Cell is Empty or Not in Excel

Tutorial: How to check if a cell is empty or is not empty in Excel; this tutorial shows you a couple…

Sum Values from Every X Number of Rows in Excel

Tutorial: Add values from every x number of rows in Excel. For instance, add together every other va…

Subscribe for Weekly Tutorials

BONUS: subscribe now to download our Top Tutorials Ebook!

The COUNTIF function counts cells in a range that meet a given condition, referred to as criteria. COUNTIF is a common, widely used function in Excel, and can be used to count cells that contain dates, numbers, and text. Note that COUNTIF can only apply a single condition. To count cells with multiple criteria, see the COUNTIFS function.

Syntax

The generic syntax for COUNTIF looks like this:

=COUNTIF(range,criteria)

The COUNTIF function takes two arguments, range and criteria. Range is the range of cells to apply a condition to. Criteria is the condition to apply, along with any logical operators that are needed.

Applying criteria

The COUNTIF function supports logical operators (>,<,<>,<=,>=) and wildcards (*,?) for partial matching. The tricky part about using the COUNTIF function is the syntax used to apply criteria. COUNTIFS is in a group of eight functions that split logical criteria into two parts, range and criteria. Because of this design, each condition requires a separate range and criteria argument, and operators in the criteria must be enclosed in double quotes («»). The table below shows examples of the syntax needed for common criteria:

Target Criteria
Cells greater than 75 «>75»
Cells equal to 100 100 or «100»
Cells less than or equal to 100 «<=100»
Cells equal to «Red» «red»
Cells not equal to «Red» «<>red»
Cells that are blank «» «»
Cells that are not blank «<>»
Cells that begin with «X» «x*»
Cells less than A1 «<«&A1
Cells less than today «<«&TODAY()

Notice the last two examples involve concatenation with the ampersand (&) character.  Any time you are using a value from another cell, or using the result of a formula in criteria with a logical operator like «<«, you will need to concatenate. This is because Excel needs to evaluate cell references and formulas first to get a value, before that value can be joined to an operator.

Basic example

In the worksheet shown above, the following formulas are used in cells G5, G6, and G7:

=COUNTIF(D5:D12,">100") // count sales over 100
=COUNTIF(B5:B12,"jim") // count name = "jim"
=COUNTIF(C5:C12,"ca") // count state = "ca"

Notice COUNTIF is not case-sensitive, «CA» and «ca» are treated the same.

Double quotes («») in criteria

In general, text values need to be enclosed in double quotes («»), and numbers do not. However, when a logical operator is included with a number, the number and operator must be enclosed in quotes, as seen in the second example below:

=COUNTIF(A1:A10,100) // count cells equal to 100
=COUNTIF(A1:A10,">32") // count cells greater than 32
=COUNTIF(A1:A10,"jim") // count cells equal to "jim"

Value from another cell

A value from another cell can be included in criteria using concatenation. In the example below, COUNTIF will return the count of values in A1:A10 that are less than the value in cell B1. Notice the less than operator (which is text) is enclosed in quotes.

=COUNTIF(A1:A10,"<"&B1) // count cells less than  B1

Not equal to

To construct «not equal to» criteria, use the «<>» operator surrounded by double quotes («»). For example, the formula below will count cells not equal to «red» in the range A1:A10:

=COUNTIF(A1:A10,"<>red") // not "red"

Blank cells

COUNTIF can count cells that are blank or not blank. The formulas below count blank and not blank cells in the range A1:A10:

=COUNTIF(A1:A10,"<>") // not blank
=COUNTIF(A1:A10,"") // blank

Note: be aware that COUNTIF treats formulas that return an empty string («») as not blank. See this example for some workarounds to this problem.

Dates

The easiest way to use COUNTIF with dates is to refer to a valid date in another cell with a cell reference. For example, to count cells in A1:A10 that contain a date greater than the date in B1, you can use a formula like this:

=COUNTIF(A1:A10, ">"&B1) // count dates greater than A1

Notice we must concatenate an operator to the date in B1. To use more advanced date criteria (i.e. all dates in a given month, or all dates between two dates) you’ll want to switch to the COUNTIFS function, which can handle multiple criteria.

The safest way to hardcode a date into COUNTIF is to use the DATE function. This ensures Excel will understand the date. To count cells in A1:A10 that contain a date less than April 1, 2020, you can use a formula like this

=COUNTIF(A1:A10,"<"&DATE(2020,4,1)) // dates less than 1-Apr-2020

Wildcards

The wildcard characters question mark (?), asterisk(*), or tilde (~) can be used in criteria. A question mark (?) matches any one character and an asterisk (*) matches zero or more characters of any kind. For example, to count cells in A1:A5 that contain the text «apple» anywhere, you can use a formula like this:

=COUNTIF(A1:A5,"*apple*") // cells that contain "apple"

To count cells in A1:A5 that contain any 3 text characters, you can use:

=COUNTIF(A1:A5,"???") // cells that contain any 3 characters

The tilde (~) is an escape character to match literal wildcards. For example, to count a literal question mark (?), asterisk(*), or tilde (~), add a tilde in front of the wildcard (i.e. ~?, ~*, ~~).

OR logic

The COUNTIF function is designed to apply just one condition. However, to count cells that contain «this OR that», you can use an array constant and the SUM function like this:

=SUM(COUNTIF(range,{"red","blue"})) // red or blue

The formula above will count cells in range that contain «red» or «blue». Essentially, COUNTIF returns two counts in an array (one for «red» and one for «blue») and the SUM function returns the sum. For more information, see this example.

Limitations

The COUNTIF function has some limitations you should be aware of:

  • COUNTIF only supports a single condition. If you need to count cells using multiple criteria, use the COUNTIFS function.
  • COUNTIF requires an actual range for the range argument; you can’t provide an array. This means you can’t alter values in range before applying criteria.
  • COUNTIF is not case-sensitive. Use the EXACT function for case-sensitive counts.
  • COUNTIFS has other quirks explained in this article.

The most common way to work around the limitations above is to use the SUMPRODUCT function. In the current version of Excel, another option is to use the newer BYROW and BYCOL functions.

Notes

  • Text strings in criteria must be enclosed in double quotes («»), i.e. «apple», «>32», «app*»
  • Cell references in criteria are not enclosed in quotes, i.e. «<«&A1
  • The wildcard characters ? and * can be used in criteria. A question mark matches any one character and an asterisk matches any sequence of characters (zero or more).
  • To match a literal question mark(?) or asterisk (*), use a tilde (~) like (~?, ~*).
  • COUNTIF requires a range, you can’t substitute an array.
  • COUNTIF returns incorrect results when used to match strings longer than 255 characters.
  • COUNTIF will return a #VALUE error when referencing another workbook that is closed.

Содержание

  1. Ways to count values in a worksheet
  2. Download our examples
  3. In this article
  4. Simple counting
  5. Video: Count cells by using the Excel status bar
  6. Use AutoSum
  7. Add a Subtotal row
  8. Count cells in a list or Excel table column by using the SUBTOTAL function
  9. Counting based on one or more conditions
  10. Video: Use the COUNT, COUNTIF, and COUNTA functions
  11. Count cells in a range by using the COUNT function
  12. Count cells in a range based on a single condition by using the COUNTIF function
  13. Count cells in a column based on single or multiple conditions by using the DCOUNT function
  14. Count cells in a range based on multiple conditions by using the COUNTIFS function
  15. Count based on criteria by using the COUNT and IF functions together
  16. Count how often multiple text or number values occur by using the SUM and IF functions together
  17. Count cells in a column or row in a PivotTable
  18. Counting when your data contains blank values
  19. Count nonblank cells in a range by using the COUNTA function
  20. Count nonblank cells in a list with specific conditions by using the DCOUNTA function
  21. Count blank cells in a contiguous range by using the COUNTBLANK function
  22. Count blank cells in a non-contiguous range by using a combination of SUM and IF functions
  23. Counting unique occurrences of values
  24. Count the number of unique values in a list column by using Advanced Filter
  25. Count the number of unique values in a range that meet one or more conditions by using IF, SUM, FREQUENCY, MATCH, and LEN functions
  26. Special cases (count all cells, count words)
  27. Count the total number of cells in a range by using ROWS and COLUMNS functions
  28. Count words in a range by using a combination of SUM, IF, LEN, TRIM, and SUBSTITUTE functions
  29. Displaying calculations and counts on the status bar
  30. Need more help?

Ways to count values in a worksheet

Counting is an integral part of data analysis, whether you are tallying the head count of a department in your organization or the number of units that were sold quarter-by-quarter. Excel provides multiple techniques that you can use to count cells, rows, or columns of data. To help you make the best choice, this article provides a comprehensive summary of methods, a downloadable workbook with interactive examples, and links to related topics for further understanding.

Note: Counting should not be confused with summing. For more information about summing values in cells, columns, or rows, see Summing up ways to add and count Excel data.

Download our examples

You can download an example workbook that gives examples to supplement the information in this article. Most sections in this article will refer to the appropriate worksheet within the example workbook that provides examples and more information.

In this article

Simple counting

You can count the number of values in a range or table by using a simple formula, clicking a button, or by using a worksheet function.

Excel can also display the count of the number of selected cells on the Excel status bar. See the video demo that follows for a quick look at using the status bar. Also, see the section Displaying calculations and counts on the status bar for more information. You can refer to the values shown on the status bar when you want a quick glance at your data and don’t have time to enter formulas.

Video: Count cells by using the Excel status bar

Watch the following video to learn how to view count on the status bar.

Use AutoSum

Use AutoSum by selecting a range of cells that contains at least one numeric value. Then on the Formulas tab, click AutoSum > Count Numbers.

Excel returns the count of the numeric values in the range in a cell adjacent to the range you selected. Generally, this result is displayed in a cell to the right for a horizontal range or in a cell below for a vertical range.

Add a Subtotal row

You can add a subtotal row to your Excel data. Click anywhere inside your data, and then click Data > Subtotal.

Note: The Subtotal option will only work on normal Excel data, and not Excel tables, PivotTables, or PivotCharts.

Also, refer to the following articles:

Count cells in a list or Excel table column by using the SUBTOTAL function

Use the SUBTOTAL function to count the number of values in an Excel table or range of cells. If the table or range contains hidden cells, you can use SUBTOTAL to include or exclude those hidden cells, and this is the biggest difference between SUM and SUBTOTAL functions.

The SUBTOTAL syntax goes like this:

To include hidden values in your range, you should set the function_num argument to 2.

To exclude hidden values in your range, set the function_num argument to 102.

Counting based on one or more conditions

You can count the number of cells in a range that meet conditions (also known as criteria) that you specify by using a number of worksheet functions.

Video: Use the COUNT, COUNTIF, and COUNTA functions

Watch the following video to see how to use the COUNT function and how to use the COUNTIF and COUNTA functions to count only the cells that meet conditions you specify.

Count cells in a range by using the COUNT function

Use the COUNT function in a formula to count the number of numeric values in a range.

In the above example, A2, A3, and A6 are the only cells that contains numeric values in the range, hence the output is 3.

Note: A7 is a time value, but it contains text ( a.m.), hence COUNT does not consider it a numerical value. If you were to remove a.m. from the cell, COUNT will consider A7 as a numerical value, and change the output to 4.

Count cells in a range based on a single condition by using the COUNTIF function

Use the COUNTIF function function to count how many times a particular value appears in a range of cells.

Count cells in a column based on single or multiple conditions by using the DCOUNT function

DCOUNT function counts the cells that contain numbers in a field (column) of records in a list or database that match conditions that you specify.

In the following example, you want to find the count of the months including or later than March 2016 that had more than 400 units sold. The first table in the worksheet, from A1 to B7, contains the sales data.

DCOUNT uses conditions to determine where the values should be returned from. Conditions are typically entered in cells in the worksheet itself, and you then refer to these cells in the criteria argument. In this example, cells A10 and B10 contain two conditions—one that specifies that the return value must be greater than 400, and the other that specifies that the ending month should be equal to or greater than March 31st, 2016.

You should use the following syntax:

DCOUNT checks the data in the range A1 through B7, applies the conditions specified in A10 and B10, and returns 2, the total number of rows that satisfy both conditions (rows 5 and 7).

Count cells in a range based on multiple conditions by using the COUNTIFS function

The COUNTIFS function is similar to the COUNTIF function with one important exception: COUNTIFS lets you apply criteria to cells across multiple ranges and counts the number of times all criteria are met. You can use up to 127 range/criteria pairs with COUNTIFS.

The syntax for COUNTIFS is:

COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2],…)

See the following example:

Count based on criteria by using the COUNT and IF functions together

Let’s say you need to determine how many salespeople sold a particular item in a certain region or you want to know how many sales over a certain value were made by a particular salesperson. You can use the IF and COUNT functions together; that is, you first use the IF function to test a condition and then, only if the result of the IF function is True, you use the COUNT function to count cells.

The formulas in this example must be entered as array formulas. If you have opened this workbook in Excel for Windows or Excel 2016 for Mac and want to change the formula or create a similar formula, press F2, and then press Ctrl+Shift+Enter to make the formula return the results you expect. In earlier versions of Excel for Mac, use +Shift+Enter.

For the example formulas to work, the second argument for the IF function must be a number.

Count how often multiple text or number values occur by using the SUM and IF functions together

In the examples that follow, we use the IF and SUM functions together. The IF function first tests the values in some cells and then, if the result of the test is True, SUM totals those values that pass the test.

The above function says if C2:C7 contains the values Buchanan and Dodsworth, then the SUM function should display the sum of records where the condition is met. The formula finds three records for Buchanan and one for Dodsworth in the given range, and displays 4.

The above function says if D2:D7 contains values lesser than $9000 or greater than $19,000, then SUM should display the sum of all those records where the condition is met. The formula finds two records D3 and D5 with values lesser than $9000, and then D4 and D6 with values greater than $19,000, and displays 4.

The above function says if D2:D7 has invoices for Buchanan for less than $9000, then SUM should display the sum of records where the condition is met. The formula finds that C6 meets the condition, and displays 1.

Important: The formulas in this example must be entered as array formulas. That means you press F2 and then press Ctrl+Shift+Enter. In earlier versions of Excel for Mac use +Shift+Enter.

See the following Knowledge Base articles for additional tips:

Count cells in a column or row in a PivotTable

A PivotTable summarizes your data and helps you analyze and drill down into your data by letting you choose the categories on which you want to view your data.

You can quickly create a PivotTable by selecting a cell in a range of data or Excel table and then, on the Insert tab, in the Tables group, clicking PivotTable.

Let’s look at a sample scenario of a Sales spreadsheet, where you can count how many sales values are there for Golf and Tennis for specific quarters.

Note: For an interactive experience, you can run these steps on the sample data provided in the PivotTable sheet in the downloadable workbook.

Enter the following data in an Excel spreadsheet.

Click Insert > PivotTable.

In the Create PivotTable dialog box, click Select a table or range, then click New Worksheet, and then click OK.

An empty PivotTable is created in a new sheet.

In the PivotTable Fields pane, do the following:

Drag Sport to the Rows area.

Drag Quarter to the Columns area.

Drag Sales to the Values area.

The field name displays as SumofSales2 in both the PivotTable and the Values area.

At this point, the PivotTable Fields pane looks like this:

In the Values area, click the dropdown next to SumofSales2 and select Value Field Settings.

In the Value Field Settings dialog box, do the following:

In the Summarize value field by section, select Count.

In the Custom Name field, modify the name to Count.

The PivotTable displays the count of records for Golf and Tennis in Quarter 3 and Quarter 4, along with the sales figures.

Counting when your data contains blank values

You can count cells that either contain data or are blank by using worksheet functions.

Count nonblank cells in a range by using the COUNTA function

Use the COUNTA function function to count only cells in a range that contain values.

When you count cells, sometimes you want to ignore any blank cells because only cells with values are meaningful to you. For example, you want to count the total number of salespeople who made a sale (column D).

COUNTA ignores the blank values in D3, D4, D8, and D11, and counts only the cells containing values in column D. The function finds six cells in column D containing values and displays 6 as the output.

Count nonblank cells in a list with specific conditions by using the DCOUNTA function

Use the DCOUNTA function to count nonblank cells in a column of records in a list or database that match conditions that you specify.

The following example uses the DCOUNTA function to count the number of records in the database that is contained in the range A1:B7 that meet the conditions specified in the criteria range A9:B10. Those conditions are that the Product ID value must be greater than or equal to 2000 and the Ratings value must be greater than or equal to 50.

DCOUNTA finds two rows that meet the conditions- rows 2 and 4, and displays the value 2 as the output.

Count blank cells in a contiguous range by using the COUNTBLANK function

Use the COUNTBLANK function function to return the number of blank cells in a contiguous range (cells are contiguous if they are all connected in an unbroken sequence). If a cell contains a formula that returns empty text («»), that cell is counted.

When you count cells, there may be times when you want to include blank cells because they are meaningful to you. In the following example of a grocery sales spreadsheet. suppose you want to find out how many cells don’t have the sales figures mentioned.

Note: The COUNTBLANK worksheet function provides the most convenient method for determining the number of blank cells in a range, but it doesn’t work very well when the cells of interest are in a closed workbook or when they do not form a contiguous range. The Knowledge Base article XL: When to Use SUM(IF()) instead of CountBlank() shows you how to use a SUM(IF()) array formula in those cases.

Count blank cells in a non-contiguous range by using a combination of SUM and IF functions

Use a combination of the SUM function and the IF function. In general, you do this by using the IF function in an array formula to determine whether each referenced cell contains a value, and then summing the number of FALSE values returned by the formula.

See a few examples of SUM and IF function combinations in an earlier section Count how often multiple text or number values occur by using the SUM and IF functions together in this topic.

Counting unique occurrences of values

You can count unique values in a range by using a PivotTable, COUNTIF function, SUM and IF functions together, or the Advanced Filter dialog box.

Count the number of unique values in a list column by using Advanced Filter

Use the Advanced Filter dialog box to find the unique values in a column of data. You can either filter the values in place or you can extract and paste them to a new location. Then you can use the ROWS function to count the number of items in the new range.

To use Advanced Filter, click the Data tab, and in the Sort & Filter group, click Advanced.

The following figure shows how you use the Advanced Filter to copy only the unique records to a new location on the worksheet.

In the following figure, column E contains the values that were copied from the range in column D.

If you filter your data in place, values are not deleted from your worksheet — one or more rows might be hidden. Click Clear in the Sort & Filter group on the Data tab to display those values again.

If you only want to see the number of unique values at a quick glance, select the data after you have used the Advanced Filter (either the filtered or the copied data) and then look at the status bar. The Count value on the status bar should equal the number of unique values.

Count the number of unique values in a range that meet one or more conditions by using IF, SUM, FREQUENCY, MATCH, and LEN functions

Use various combinations of the IF, SUM, FREQUENCY, MATCH, and LEN functions.

For more information and examples, see the section «Count the number of unique values by using functions» in the article Count unique values among duplicates.

Special cases (count all cells, count words)

You can count the number of cells or the number of words in a range by using various combinations of worksheet functions.

Count the total number of cells in a range by using ROWS and COLUMNS functions

Suppose you want to determine the size of a large worksheet to decide whether to use manual or automatic calculation in your workbook. To count all the cells in a range, use a formula that multiplies the return values using the ROWS and COLUMNS functions. See the following image for an example:

Count words in a range by using a combination of SUM, IF, LEN, TRIM, and SUBSTITUTE functions

You can use a combination of the SUM, IF, LEN, TRIM, and SUBSTITUTE functions in an array formula. The following example shows the result of using a nested formula to find the number of words in a range of 7 cells (3 of which are empty). Some of the cells contain leading or trailing spaces — the TRIM and SUBSTITUTE functions remove these extra spaces before any counting occurs. See the following example:

Now, for the above formula to work correctly, you have to make this an array formula, otherwise the formula returns the #VALUE! error. To do that, click on the cell that has the formula, and then in the Formula bar, press Ctrl + Shift + Enter. Excel adds a curly bracket at the beginning and the end of the formula, thus making it an array formula.

For more information on array formulas, see Overview of formulas in Excel and Create an array formula.

Displaying calculations and counts on the status bar

When one or more cells are selected, information about the data in those cells is displayed on the Excel status bar. For example, if four cells on your worksheet are selected, and they contain the values 2, 3, a text string (such as «cloud»), and 4, all of the following values can be displayed on the status bar at the same time: Average, Count, Numerical Count, Min, Max, and Sum. Right-click the status bar to show or hide any or all of these values. These values are shown in the illustration that follows.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Источник

Author: Oscar Cronquist Article last updated on September 17, 2021

The image above demonstrates a formula that matches a value to multiple conditions, if the condition is met the formula takes the value in a corresponding cell on the same row and adds a given number.

Table of contents

  1. Use IF + COUNTIF to evaluate multiple conditions
    1. Explaining formula
  2. Use IF + COUNTIF to evaluate multiple conditions and different outcomes
    1. Explaining formula
  3. Get Excel file

The COUNTIF function allows you to construct a small IF formula that carries out plenty of logical expressions.

Combining the IF and COUNTIF functions also let you have more than 254 logical expressions and the effort to type the formula is minimal.

1. Use IF + COUNTIF to evaluate multiple conditions

=IF(COUNTIF($B$23:$D$25,B3),C3+100,»»)

The example shown in the above picture checks if the country in cell B3 is equal to one of the countries in cell range B23:D25.

In other words, the COUNTIF function counts how many times a specific value is found in a cell range.

If the value exists at least once in the cell range the IF function adds 100 to the value in C3. If FALSE the formula returns a blank.

Back to top

1.1 Explaining formula in cell D3

Step 1 — COUNTIF function syntax

The COUNTIF function calculates the number of cells that is equal to a condition.

COUNTIF(rangecriteria)

Step 2 — Populate COUNTIF function arguments

COUNTIF(rangecriteria)

becomes

COUNTIF($B$23:$D$25,B3)

range — A reference to all conditions: $B$23:$D$25

criteria — The value to match.

Step 3 — Evaluate COUNTIF function

COUNTIF($B$23:$D$25,B3)

becomes

COUNTIF({«Cambodia«, «Sri Lanka», «Japan»; «Mongolia», «Bangladesh», «Philippines»; «Laos», «India», «Indonesia»}, «Cambodia«)

and returns 1. The criteria value is found once in the array (bolded).

Step 4 — IF function syntax

The IF function returns one value if the logical test is TRUE and another value if the logical test is FALSE.

IF(logical_test, [value_if_true], [value_if_false])

Step 5 — Populate IF function arguments

IF(logical_test, [value_if_true], [value_if_false])

becomes

IF(1, C3+100, «»)

logical_test — True or False, the numerical equivalents are TRUE — 1 and False — 0 (zero). 1, in this case, is equal to TRUE.

[value_if_true] — C3+100, add 100 to value in cell C3.

[value_if_false] — «».

Step 6 — Evaluate IF function

IF(COUNTIF($B$23:$D$25, B3), C3+100, «»)

becomes

IF(1, C3+100, «»)

becomes

C3 + 100

becomes

99 + 100

and returns 199 in cell D3.

Back to top

2. Use IF + COUNTIF to evaluate multiple conditions and calculate different outcomes

Use IF and COUNTIF to evaluate multiple conditions and different outcomes

The image above demonstrates a formula in cell D3 that checks if the value in cell B3 matches any of the conditions specified in cell range F4:F12. If so, add the corresponding number in cell range G4:G12 to the number in cell C3.

Formula in cell D3:

=IF(COUNTIF($F$4:$F$12, B3), C3+INDEX($G$4:$G$12, MATCH(B3, $F$4:$F$12,0)), «»)

Back to top

2.1 Explaining formula

Step 1 — Check if the value matches any of the conditions

The COUNTIF function calculates the number of cells that is equal to a condition.

COUNTIF(rangecriteria)

COUNTIF($F$4:$F$12, B3)

becomes

COUNTIF({«Cambodia«; «Mongolia»; «Laos»; «Sri Lanka»; «Bangladesh»; «India»; «Japan»; «Philippines»; «Indonesia»}, «Cambodia«)

and returns 1. This means that there is one value that matches.

Step 2 — IF function

The IF function returns one value if the logical test is TRUE and another value if the logical test is FALSE.

IF(logical_test, [value_if_true], [value_if_false])

IF(COUNTIF($F$4:$F$12, B3), [value_if_true], [value_if_false])

becomes

IF(1, [value_if_true], [value_if_false])

[value_if_true] — C3+INDEX($G$4:$G$12, MATCH(B3, $F$4:$F$12,0))

[value_if_false] — «»

Step 3 — Calculate the relative position of a lookup value

The MATCH function returns the relative position of an item in an array or cell reference that matches a specified value in a specific order.

MATCH(lookup_value, lookup_array, [match_type])

MATCH(B3, $F$4:$F$12,0)

becomes

MATCH(«Cambodia», {«Cambodia»; «Mongolia»; «Laos»; «Sri Lanka»; «Bangladesh»; «India»; «Japan»; «Philippines»; «Indonesia»}, 0)

and returns 1. The lookup value is found at the first position in the array.

Step 3 — Get value

The INDEX function returns a value from a cell range, you specify which value based on a row and column number.

INDEX(array, [row_num], [column_num])

INDEX($G$4:$G$12, MATCH(B3, $F$4:$F$12,0))

becomes

INDEX($G$4:$G$12, 1)

and returns 27.

Step 4 — Add values

The plus sign lets you add numbers in an Excel formula.

C3+INDEX($G$4:$G$12, MATCH(B3, $F$4:$F$12,0))

becomes

99 + 27 equals 126.

Back to top

Get Excel *.xlsx file

Use IF + COUNTIF to perform multiple conditionsv2

Back to top

Понравилась статья? Поделить с друзьями:
  • Count if this and this excel
  • Count if there is a value excel
  • Count if number between excel
  • Count if not text excel
  • Count if not number excel