Test for a specific condition
=IF(logical_test, [value_if_true], [value_if_false])
| Parameter | Description |
|---|---|
logical_test |
A value or logical expression that can be evaluated as TRUE or FALSE. |
value_if_true |
[optional] The value to return when logical_test evaluates to TRUE. |
value_if_false |
[optional] The value to return when logical_test evaluates to FALSE. |
To understand how the IF function works, let's start with a very basic example. In the worksheet below, the goal is to use the IF function to mark sco
=IF(B5>80,TRUE)
Note we are not using quotes ("") anywhere in the formula because the formula contains no text. Also, we do not need to provide a value for value_if_f
=IF(B5>80,"x")
Note that TRUE values have been replaced by "x", and the FALSE results remain FALSE since we have not provided a value for value_if_false. Finally, le
=IF(B5>80,"x","")
In the worksheet below, we want to assign either a "Pass" or "Fail" based on a test score. A passing score is 70 or higher. The formula in E5, copied
=IF(C5<70,"Fail","Pass")
Notice both "Pass" and "Fail" are in double quotes ("") because they are text values. Also, note that the logical flow of this formula can be reversed
=IF(C5>=70,"Pass","Fail")
A common challenge with the IF function is how to handle a problem that requires "if this or that" logic. The logical test for IF takes just one value
=IF(OR(B5="red",B5="green"),"x","")