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.

All current Excel versions. Also in Excel for the web and Google Sheets.

Syntax =IF(logical_test, value_if_true, [value_if_false])

IF
=IF(B2>B1,"Over","OK")

Arguments

NameRequiredWhat to pass
logical_testRequiredA test that is TRUE or FALSE, such as B2>B1.
value_if_trueRequiredWhat to return when the test is TRUE.
value_if_falseOptionalWhat 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

=IF(B2>B1,"Over","OK")B3
Budget check
AB
1Planned650
2Actual712
3StatusOver
A picture of the sheet. 712 is greater than 650, so the test is true.

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.