- What If?
- Using More Advanced Conditions
- Nesting IF() Functions
- In Conclusion
Using More Advanced Conditions
So far, you have seen examples of the IF() function that use a single condition, and this is probably what you’ll use most of the time. You can also combine multiple conditions using the AND() and OR() functions. These functions have the same syntax:
OR(cond1, cond2, ....) AND(cond1, cond2, ....)
In both cases, cond1 and cond2 are each an independent logical expression that evaluates to True or False. You can have as many as 30 conditions as arguments for the OR() and AND() functions. The return of these functions is the following:
- OR() returns True if one or more of its arguments is True. It returns False only if all of its arguments are False.
- AND() returns False if one or more of its arguments is False. It returns True only if all of its arguments are True.
Here are some examples of using AND() and OR() with the IF() function. This IF() function displays "OK" only if cells A1 and A2 both contain values greater than 0; otherwise, it displays "Warning!".
This example displays "Invalid" if any one of the cells B10, B11, or B12 contains a value less than 0. Otherwise, it displays the sum of those three cells:
=IF(OR(B10<0,B11<0,B12<0), "Invalid", SUM(B10:B12))