Excel: How to Use the IF Function (with Worked Examples)
You want a cell to show one thing when a condition is met and something else when it isn’t.
Why: IF is how Excel makes decisions. It checks a condition you write, then returns your “true” answer or your “false” answer. Once you can read its three parts, most other logical formulas make sense too.
Step 1: Learn the syntax
The IF function takes three arguments:
=IF(logical_test, value_if_true, [value_if_false])
- logical_test — the condition to check (for example,
C2="Yes"orC2>B2). - value_if_true — what to return when the condition is true.
- value_if_false — what to return otherwise (optional, but almost always worth filling in).
The single rule that trips people up: any text you return must be wrapped in double quotes — "Yes", "Over Budget". The only exceptions are TRUE and FALSE, which Excel understands on their own.
Step 2: A worked example
Suppose column B holds a budget and column C holds the actual spend. You want a plain-English verdict in column D.
-
Click cell D2.
-
Type:
=IF(C2>B2,"Over Budget","Within Budget") -
Press Enter, then drag the fill handle down column D.
For each row Excel checks whether the actual (C) exceeds the budget (B). If it does, the cell reads Over Budget; if not, Within Budget.
Step 3: Return numbers and calculations, not just text
The two results can be numbers or even formulas:
-
Return a number based on a yes/no cell:
=IF(C2="Yes",1,2) -
Show the overspend amount, or zero if on budget:
=IF(C2>B2,C2-B2,0) -
Apply tax only when a cell says “Yes”:
=IF(E7="Yes",F5*0.0825,0)
The “true” and “false” slots can each be a value, a piece of text, or another calculation.
FAQ
Can I test more than one condition? Yes — nest IF functions, for example =IF(C2>90,"A",IF(C2>80,"B","C")), or combine IF with AND/OR like =IF(AND(C2>0,B2>0),"OK","Check"). Excel allows up to 64 nested IFs, but the IFS function is usually cleaner for many tiers.
My text result shows a #NAME? error. You forgot the quotation marks around text. Write "Yes", not Yes.
Both branches return the same answer unexpectedly. Re-check the logical_test operator (>, <, =, >=) and whether you’re comparing text to text or number to number — "5" (text) and 5 (number) are not equal.
Sources: Microsoft Support — IF function · Microsoft Support — Using IF with AND, OR and NOT functions