Using IF with AND, OR, and NOT functions in Excel (2024)

In Excel, the IF function allows you to make a logical comparison between a value and what you expect by testing for a condition and returning a result if that condition is True or False.

  • =IF(Something is True, then do something, otherwise do something else)

But what if you need to test multiple conditions, where let’s say all conditions need to be True or False (AND), or only one condition needs to be True or False (OR), or if you want to check if a condition does NOT meet your criteria? All 3 functions can be used on their own, but it’s much more common to see them paired with IF functions.

Use the IF function along with AND, OR and NOT to perform multiple evaluations if conditions are True or False.

Syntax

Argument name

Description

logical_test (required)

The condition you want to test.

value_if_true (required)

The value that you want returned if the result of logical_test is TRUE.

value_if_false (optional)

The value that you want returned if the result of logical_test is FALSE.

Here are overviews of how to structure AND, OR and NOT functions individually. When you combine each one of them with an IF statement, they read like this:

  • AND – =IF(AND(Something is True, Something else is True), Value if True, Value if False)

  • OR – =IF(OR(Something is True, Something else is True), Value if True, Value if False)

  • NOT – =IF(NOT(Something is True), Value if True, Value if False)

Examples

Following are examples of some common nested IF(AND()), IF(OR()) and IF(NOT()) statements in Excel. The AND and OR functions can support up to 255 individual conditions, but it’s not good practice to use more than a few because complex, nested formulas can get very difficult to build, test and maintain. The NOT function only takes one condition.

Using IF with AND, OR, and NOT functions in Excel (1)

Here are the formulas spelled out according to their logic:

Formula

Description

=IF(AND(A2>0,B2<100),TRUE, FALSE)

IF A2 (25) is greater than 0, AND B2 (75) is less than 100, then return TRUE, otherwise return FALSE. In this case both conditions are true, so TRUE is returned.

=IF(AND(A3="Red",B3="Green"),TRUE,FALSE)

If A3 (“Blue”) = “Red”, AND B3 (“Green”) equals “Green” then return TRUE, otherwise return FALSE. In this case only the first condition is true, so FALSE is returned.

=IF(OR(A4>0,B4<50),TRUE, FALSE)

IF A4 (25) is greater than 0, OR B4 (75) is less than 50, then return TRUE, otherwise return FALSE. In this case, only the first condition is TRUE, but since OR only requires one argument to be true the formula returns TRUE.

=IF(OR(A5="Red",B5="Green"),TRUE,FALSE)

IF A5 (“Blue”) equals “Red”, OR B5 (“Green”) equals “Green” then return TRUE, otherwise return FALSE. In this case, the second argument is True, so the formula returns TRUE.

=IF(NOT(A6>50),TRUE,FALSE)

IF A6 (25) is NOT greater than 50, then return TRUE, otherwise return FALSE. In this case 25 is not greater than 50, so the formula returns TRUE.

=IF(NOT(A7="Red"),TRUE,FALSE)

IF A7 (“Blue”) is NOT equal to “Red”, then return TRUE, otherwise return FALSE.

Note that all of the examples have a closing parenthesis after their respective conditions are entered. The remaining True/False arguments are then left as part of the outer IF statement. You can also substitute Text or Numeric values for the TRUE/FALSE values to be returned in the examples.

Here are some examples of using AND, OR and NOT to evaluate dates.

Using IF with AND, OR, and NOT functions in Excel (2)

Here are the formulas spelled out according to their logic:

Formula

Description

=IF(A2>B2,TRUE,FALSE)

IF A2 is greater than B2, return TRUE, otherwise return FALSE. 03/12/14 is greater than 01/01/14, so the formula returns TRUE.

=IF(AND(A3>B2,A3<C2),TRUE,FALSE)

IF A3 is greater than B2 AND A3 is less than C2, return TRUE, otherwise return FALSE. In this case both arguments are true, so the formula returns TRUE.

=IF(OR(A4>B2,A4<B2+60),TRUE,FALSE)

IF A4 is greater than B2 OR A4 is less than B2 + 60, return TRUE, otherwise return FALSE. In this case the first argument is true, but the second is false. Since OR only needs one of the arguments to be true, the formula returns TRUE. If you use the Evaluate Formula Wizard from the Formula tab you'll see how Excel evaluates the formula.

=IF(NOT(A5>B2),TRUE,FALSE)

IF A5 is not greater than B2, then return TRUE, otherwise return FALSE. In this case, A5 is greater than B2, so the formula returns FALSE.

Using IF with AND, OR, and NOT functions in Excel (3)

Using AND, OR and NOT with Conditional Formatting in Excel

In Excel, you can also use AND, OR and NOT to set Conditional Formatting criteria with the formula option. When you do this you can omit the IF function and use AND, OR and NOT on their own.

In Excel, from the Home tab, click Conditional Formatting > New Rule. Next, select the “Use a formula to determine which cells to format” option, enter your formula and apply the format of your choice.

Using IF with AND, OR, and NOT functions in Excel (4)

Using the earlier Dates example, here is what the formulas would be.

Using IF with AND, OR, and NOT functions in Excel (5)

Formula

Description

=A2>B2

If A2 is greater than B2, format the cell, otherwise do nothing.

=AND(A3>B2,A3<C2)

If A3 is greater than B2 AND A3 is less than C2, format the cell, otherwise do nothing.

=OR(A4>B2,A4<B2+60)

If A4 is greater than B2 OR A4 is less than B2 plus 60 (days), then format the cell, otherwise do nothing.

=NOT(A5>B2)

If A5 is NOT greater than B2, format the cell, otherwise do nothing. In this case A5 is greater than B2, so the result will return FALSE. If you were to change the formula to =NOT(B2>A5) it would return TRUE and the cell would be formatted.

Note:A common error is to enter your formula into Conditional Formatting without the equals sign (=). If you do this you’ll see that the Conditional Formatting dialog will add the equals sign and quotes to the formula - ="OR(A4>B2,A4<B2+60)", so you’ll need to remove the quotes before the formula will respond properly.

Need more help?

See also

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

Learn how to use nested functions in a formula

IF function

AND function

OR function

NOT function

Overview of formulas in Excel

How to avoid broken formulas

Detect errors in formulas

Keyboard shortcuts in Excel

Logical functions (reference)

Excel functions (alphabetical)

Excel functions (by category)

Using IF with AND, OR, and NOT functions in Excel (2024)

FAQs

How do you use if function with and or and not in Excel? ›

When you combine each one of them with an IF statement, they read like this: AND – =IF(AND(Something is True, Something else is True), Value if True, Value if False) OR – =IF(OR(Something is True, Something else is True), Value if True, Value if False)

Can I use if and and or in the same formula in Excel? ›

Use AND and OR with IF

You can also use AND and OR with the IF function. In this example, people don't earn bonuses until they sell at least $125,000 worth of goods, unless they work in the southern region where the market is smaller.

How to put 3 conditions in if formula in Excel? ›

To put three conditions in an IF formula in Excel, you can use nested IF functions, or use the IFS function instead. To nest multiple IF functions, use the following format =IF(logical_test1, IF(logical_test2, IF(logical_test3,…),…),…).

Can you nest the and or or functions within an if function? ›

You can automate the evaluation of logical tests by NESTING the AND, OR, NOT functions inside a single IF function. This means that if we have multiple conditions but we want to return a single output, we can nest any of the conjunction functions inside an IF and specify outputs accordingly.

What is the if formula for 2 conditions? ›

The Excel IF function with two or more conditions follows a generic formula: =IF(AND(condition1, condition2, ...), value_if_true, value_if_false). What this means is that “If condition 1 is true AND condition 2 is true, return value_if_true; else return value_if_false.”

Can I put two IF statements in Excel? ›

While Excel will allow you to nest up to 64 different IF functions, it's not at all advisable to do so. Why? Multiple IF statements require a great deal of thought to build correctly and make sure that their logic can calculate correctly through each condition all the way to the end.

How to use nested if function in Excel? ›

If you clicked IF, the Function arguments dialog box displays the arguments for the IF function. To nest another function, you can enter it into the argument box. For example, you could enter SUM(G2:G5) in the Value_if_true box of the IF function. Enter any additional arguments that are needed to complete your formula.

How do you write an if then formula in Excel? ›

Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it's false. For example: =IF(A2>B2,"Over Budget","OK") =IF(A2=B2,B4-A4,"")

How do I use multiple conditions in Excel? ›

Another way to get an Excel IF to test multiple conditions is by using an array formula. To complete an array formula correctly, press the Ctrl + Shift + Enter keys together. In Excel 365 and Excel 2021, this also works as a regular formula due to support for dynamic arrays.

How does Sumif work in Excel? ›

The SUMIFS function, one of the math and trig functions, adds all of its arguments that meet multiple criteria. For example, you would use SUMIFS to sum the number of retailers in the country who (1) reside in a single zip code and (2) whose profits exceed a specific dollar value.

Can I do a VLOOKUP with multiple criteria? ›

To Vlookup multiple criteria, you can use either an INDEX MATCH combination or the XLOOKUP function recently introduced in Office 365.

How do you combine if and or functions in Excel? ›

Can you use IF, AND, and OR together in Excel? Yes. We can use multiple logical functions with the IF function in Excel. You can combine OR and AND functions to evaluate the arguments appropriately.

How to use an if and or function in Excel? ›

How to use the OR function in Excel with the IF function
  1. Enter the IF function. Click on the cell where you want the result to appear. Type "=IF" and press "Enter" on your keyboard. ...
  2. Insert the OR function. Insert the OR function as the first argument of the IF function. ...
  3. Insert true and false values.
Jun 24, 2022

How to use ifs and or function in Excel? ›

Here's how to use the IFS function in Excel:
  1. Enter the IFS function. Click the cell where you want the function to return a value. ...
  2. Create the first logical test. Once you enter the IFS function, =IFS( appears in the cell you selected. ...
  3. Enter the first value if true. ...
  4. Enter more logical tests.
Jul 31, 2023

How to use the if function in Excel, yes or no? ›

Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it's false. For example: =IF(A2>B2,"Over Budget","OK") =IF(A2=B2,B4-A4,"")

How to write an or formula in Excel? ›

For example, A1 for either “a” or “b,” use =OR(A1=”a”,A1=”b”). The function can be used as the logical test inside the IF function to avoid extra nested IFs, and can be combined with the AND function.

How to do nested IF statements in Excel? ›

We nest an IF function by setting value_if_false to IF B2 greater than or equal to 80, return B. We use additional nested IF functions to test for C, D, and F grades. I am copying the formula. In this formula, we must test B2 greater than or equal to 90 first, and then, B2 greater than or equal to 80, and so on.

How do you insert if and and function in Excel? ›

Steps To Use IF Function In Microsoft Excel
  1. 1: Select the Spreadsheet to Insert the Formula. ...
  2. 2: From the Formula Tab, Select Insert Function → Type “IF” in the Dialog Box. ...
  3. 3: Be Sure to Keep the Cursor in the Logical_test Text Box. ...
  4. 4: Select the Cell That You Wish to Evaluate.
Apr 10, 2023

References

Top Articles
Latest Posts
Article information

Author: Roderick King

Last Updated:

Views: 6157

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Roderick King

Birthday: 1997-10-09

Address: 3782 Madge Knoll, East Dudley, MA 63913

Phone: +2521695290067

Job: Customer Sales Coordinator

Hobby: Gunsmithing, Embroidery, Parkour, Kitesurfing, Rock climbing, Sand art, Beekeeping

Introduction: My name is Roderick King, I am a cute, splendid, excited, perfect, gentle, funny, vivacious person who loves writing and wants to share my knowledge and understanding with you.