The guide · IF
How IF works
IF asks a yes-or-no question and shows one thing for yes and another for no. =IF(B2>=50, "Pass", "Fail") reads as: if B2 is 50 or more, show Pass, otherwise show Fail.
Syntax
=IF(logical_test, value_if_true, [value_if_false])
- logical_test: a comparison that is TRUE or FALSE, like
B2>=50. - value_if_true: what to show when it's true. Text goes in "double quotes".
- value_if_false: what to show otherwise. Leave it out and Excel shows FALSE.
Comparison operators
| Operator | Meaning |
|---|---|
= | equal to |
<> | not equal to |
> / < | more than / less than |
>= / <= | at least / at most |
Common mistakes
- > instead of >=. "50 or more passes" means
>=50. With>50, someone who scored exactly 50 fails. Edge cases like this are what interviewers check. - Missing quotes.
=IF(B2>=50, Pass, Fail)gives #NAME? because Excel thinks Pass is a name, not text. - Hard-coding the pass mark. Fine for practice, but in a real sheet put 50 in its own cell and point at it with
$, so it can change in one place.
FAQ
- How do I write an IF formula in Excel?
- Use =IF(test, value_if_true, value_if_false), for example =IF(B2>=50,"Pass","Fail").
- Why does my IF formula show #NAME?
- Text results must be in double quotes. Write "Pass", not Pass.