Function · Logical
Excel IF function
The Excel IF function returns one value when a condition is true and another when it is false. Includes a budget test and the blank-result trap.
Syntax =IF(logical_test, value_if_true, [value_if_false])
=IF(B2>B1,"Over","OK")Arguments
| Name | Required | What to pass |
|---|---|---|
| logical_test | Required | A test that is TRUE or FALSE, such as B2>B1. |
| value_if_true | Required | What to return when the test is TRUE. |
| value_if_false | Optional | What to return when the test is FALSE. If you omit it, Excel returns FALSE, not a blank. |
Examples
A grocery category that went over the plan
=IF(B2>B1,"Over","OK")Result Over
| A | B | |
|---|---|---|
| 1 | Planned | 650 |
| 2 | Actual | 712 |
| 3 | Status | Over |
IF is a fork. The test is the first argument. The second argument is the result when the test is true. The third is the result when it is false. On a budget sheet, =IF(B2>B1,"Over","OK") is enough to flag a category that ran past its plan. $712 against a $650 grocery plan is Over.
Leave the third argument out and a false test returns the word FALSE. That word then shows up in totals and mail-merges. Pass "" when you want the cell to look empty. A formula that returns "" is still not a blank cell. ISBLANK will say FALSE. That distinction matters when another formula is testing whether the cell was ever filled in.
Keep the tests readable. =IF(AND(B2>B1,B2<>""),"Over","OK") fails the flag when the actual cell is empty, instead of treating a blank as zero. AND and OR belong inside the test, not as a substitute for IF.