What function in microsoft Excel is used to add a certain range of cells when condition is met

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

Testing whether conditions are true or false and making logical comparisons between expressions are common to many tasks. You can use the AND, OR, NOT, and IF functions to create conditional formulas.

For example, the IF function uses the following arguments.

Formula that uses the IF function

 logical_test: The condition that you want to check.

 value_if_true: The value to return if the condition is True.

 value_if_false: The value to return if the condition is False.

For more information about how to create formulas, see Create or delete a formula.

To do this task, use the AND, OR, and NOT functions and operators as shown in the following example.

The example may be easier to understand if you copy it to a blank worksheet.

How do I copy an example?

  1. Select the example in this article.

    Selecting an example from Help

  2. Press CTRL+C.

  3. In Excel, create a blank workbook or worksheet.

  4. In the worksheet, select cell A1, and press CTRL+V.

Important: For the example to work properly, you must paste it into cell A1 of the worksheet.

  1. To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.

After you copy the example to a blank worksheet, you can adapt it to suit your needs.

Data

15

9

8

Sprockets

Widgets

Formula

Description (Result)

=AND(A2>A3, A2

Determines if the value in cell A2 is greater than the value in A3 and also if the value in A2 is less than the value in A4. (FALSE)

=OR(A2>A3, A2

Determines if the value in cell A2 is greater than the value in A3 or if the value in A2 is less than the value in A4. (TRUE)

=NOT(A2+A3=24)

Determines if the sum of the values in cells A2 and A3 is not equal to 24. (FALSE)

=NOT(A5="Sprockets")

Determines if the value in cell A5 is not equal to "Sprockets." (FALSE)

=OR(A5<>"Sprockets",A6 = "Widgets")

Determines if the value in cell A5 is not equal to "Sprockets" or if the value in A6 is equal to "Widgets." (TRUE)

For more information about how to use these functions, see AND function, OR function, and NOT function.

Top of Page

To do this task, use the IF, AND, and OR functions and operators as shown in the following example.

The example may be easier to understand if you copy it to a blank worksheet.

How do I copy an example?

  1. Select the example in this article.

    Important: Do not select the row or column headers.

    Selecting an example from Help

  2. Press CTRL+C.

  3. In Excel, create a blank workbook or worksheet.

  4. In the worksheet, select cell A1, and press CTRL+V.

Important: For the example to work properly, you must paste it into cell A1 of the worksheet.

  1. To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.

After you copy the example to a blank worksheet, you can adapt it to suit your needs.

Data

15

9

8

Sprockets

Widgets

Formula

Description (Result)

=IF(A2=15, "OK", "Not OK")

If the value in cell A2 equals 15, return "OK." Otherwise, return "Not OK." (OK)

=IF(A2<>15, "OK", "Not OK")

If the value in cell A2 is not equal to 15, return "OK." Otherwise, return "Not OK." (Not OK)

=IF(NOT(A2<=15), "OK", "Not OK")

If the value in cell A2 is not less than or equal to 15, return "OK." Otherwise, return "Not OK." (Not OK)

=IF(A5<>"SPROCKETS", "OK", "Not OK")

If the value in cell A5 is not equal to "SPROCKETS", return "OK." Otherwise, return "Not OK." (Not OK)

=IF(AND(A2>A3, A2

If the value in cell A2 is greater than the value in A3 and the value in A2 is also less than the value in A4, return "OK." Otherwise, return "Not OK." (Not OK)

=IF(AND(A2<>A3, A2<>A4), "OK", "Not OK")

If the value in cell A2 is not equal to A3 and the value in A2 is also not equal to the value in A4, return "OK." Otherwise, return "Not OK." (OK)

=IF(OR(A2>A3, A2

If the value in cell A2 is greater than the value in A3 or the value in A2 is less than the value in A4, return "OK." Otherwise, return "Not OK." (OK)

=IF(OR(A5<>"Sprockets", A6<>"Widgets"), "OK", "Not OK")

If the value in cell A5 is not equal to "Sprockets" or the value in A6 is not equal to "Widgets", return "OK." Otherwise, return "Not OK." (Not OK)

=IF(OR(A2<>A3, A2<>A4), "OK", "Not OK")

If the value in cell A2 is not equal to the value in A3 or the value in A2 is not equal to the value in A4, return "OK." Otherwise, return "Not OK." (OK)

For more information about how to use these functions, see IF function, AND function, and OR function.

Top of Page

The COUNTIFS function applies criteria to cells across multiple ranges and counts the number of times all criteria are met.

This video is part of a training course called Advanced IF functions.

Syntax

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

The COUNTIFS function syntax has the following arguments:

  • criteria_range1Required. The first range in which to evaluate the associated criteria.

  • criteria1Required. The criteria in the form of a number, expression, cell reference, or text that define which cells will be counted. For example, criteria can be expressed as 32, ">32", B4, "apples", or "32".

  • criteria_range2, criteria2, ...Optional. Additional ranges and their associated criteria. Up to 127 range/criteria pairs are allowed.

Important:Each additional range must have the same number of rows and columns as the criteria_range1 argument. The ranges do not have to be adjacent to each other.

Remarks

  • Each range's criteria is applied one cell at a time. If all of the first cells meet their associated criteria, the count increases by 1. If all of the second cells meet their associated criteria, the count increases by 1 again, and so on until all of the cells are evaluated.

  • If the criteria argument is a reference to an empty cell, the COUNTIFS function treats the empty cell as a 0 value.

  • You can use the wildcard characters— the question mark (?) and 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.

Example 1

Copy the example data in the following tables, and paste it in cell A1 of a new Excel worksheet. For formulas to show results, select them, press F2, and then press Enter. If you need to, you can adjust the column widths to see all the data.

Salesperson

Exceeded Q1 quota

Exceeded Q2 quota

Exceeded Q3 quota

Davidoski

Yes

No

No

Burke

Yes

Yes

No

Sundaram

Yes

Yes

Yes

Levitan

No

Yes

Yes

Formula

Description

Result

=COUNTIFS(B2:D2,"=Yes")

Counts how many times Davidoski exceeded a sales quota for periods Q1, Q2, and Q3 (only in Q1).

1

=COUNTIFS(B2:B5,"=Yes",C2:C5,"=Yes")

Counts how many salespeople exceeded both their Q1 and Q2 quotas (Burke and Sundaram).

2

=COUNTIFS(B5:D5,"=Yes",B3:D3,"=Yes")

Counts how many times Levitan and Burke exceeded the same quota for periods Q1, Q2, and Q3 (only in Q2).

1

Example 2

Data

1

5/1/2011

2

5/2/2011

3

5/3/2011

4

5/4/2011

5

5/5/2011

6

5/6/2011

Formula

Description

Result

=COUNTIFS(A2:A7,"<6",A2:A7,">1")

Counts how many numbers between 1 and 6 (not including 1 and 6) are contained in cells A2 through A7.

4

=COUNTIFS(A2:A7, "<5",B2:B7,"<5/3/2011")

Counts how many rows have numbers that are less than 5 in cells A2 through A7, and also have dates that are are earlier than 5/3/2011 in cells B2 through B7.

2

=COUNTIFS(A2:A7, "<" & A6,B2:B7,"<" & B4)

Same description as the previous example, but using cell references instead of constants in the criteria.

2

Need more help?

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

See Also

To count cells that aren't blank, use the COUNTA function

To count cells using a single criteria, use the COUNTIF function

The SUMIF function adds only the values that meet a single criteria

The SUMIFS function adds only the values that meet multiple criteria

IFS function (Microsoft 365, Excel 2016 and later)

Overview of formulas in Excel

How to avoid broken formulas

Detect errors in formulas

Statistical functions

Excel functions (alphabetical)

Excel functions (by Category)

How do you sum in Excel with if condition?

The SUMIF function enables us to sum values in Excel with the if condition. ... 1. Sum If Different Comparison Criteria is Required in Excel..

What is the Excel function to add numbers in a range of cells?

If you need to sum a column or row of numbers, let Excel do the math for you. Select a cell next to the numbers you want to sum, click AutoSum on the Home tab, press Enter, and you're done. When you click AutoSum, Excel automatically enters a formula (that uses the SUM function) to sum the numbers.

How do you create a range condition in Excel?

Step 1: Put the number you want to test in cell C6 (150). Step 2: Put the criteria in cells C8 and C9 (100 and 999). Step 3: Put the results if true or false in cells C11 and C12 (100 and 0). Step 4: Type the formula =IF(AND(C6>=C8,C6<=C9),C11,C12).

Which formula can be used to add a range of cells?

You can use a simple formula to sum numbers in a range (a group of cells), but the SUM function is easier to use when you're working with more than a few numbers. For example =SUM(A2:A6) is less likely to have typing errors than =A2+A3+A4+A5+A6.