GridDojo

How to Use the IF Function in Excel (with Examples)

The IF function returns one value when a condition is true and another when it is false. The syntax is =IF(logical_test, value_if_true, value_if_false). Here is how to use it, nest it, and avoid the usual mistakes.

By The GridDojo Team Published Updated 3 min read

The IF function is how you make Excel decide. It checks a condition and returns one answer if it is true and a different answer if it is false — the building block of nearly every smart spreadsheet, from pass/fail grading to flagging overdue invoices.

The IF syntax

=IF(logical_test, value_if_true, value_if_false)
The three parts of IF
PartMeaning
logical_testThe condition to check, e.g. B2>100
value_if_trueWhat to return when the condition is met
value_if_falseWhat to return when it is not

A simple example

To label sales in B2 as "Pass" or "Fail" based on a target of 100:

=IF(B2>=100, "Pass", "Fail")

Text values must go in double quotes. If you want a number instead, leave the quotes off, for example =IF(B2>=100, 1, 0).

The comparison operators you can test

Operators for the logical test
OperatorMeansExample
=equal toB2="Yes"
<>not equal toB2<>""
> <greater / less thanB2>100
>= <=at least / at mostB2>=100

Nesting IF and combining with AND / OR

You can put an IF inside another IF for more than two outcomes, or use AND and OR to test several conditions at once. To give a bonus only to VIP customers over target:

=IF(AND(B2>=100, C2="VIP"), "Bonus", "Standard")

AND requires every condition to be true; OR needs just one. For several tiers — say A/B/C grades — you can nest IFs, but they get hard to read fast. If you have Microsoft 365, the IFS function is cleaner:

=IFS(B2>=90, "A", B2>=80, "B", B2>=70, "C", TRUE, "F")

Common mistakes

  • Forgetting quotes around text — Excel reads Pass without quotes as a name and returns #NAME?.
  • Too many nested IFs — anything past three or four becomes unreadable; switch to IFS, VLOOKUP, or SWITCH.
  • Mismatched parentheses — every IF, AND, and OR needs its closing bracket.

IF pairs naturally with lookups — use it to act on the result of VLOOKUP. To hide an error inside an IF, wrap it in IFERROR; if an IF still returns #VALUE!, see how to fix the #VALUE! error.

Frequently asked questions

Can the IF function check text?

Yes. Use quotes around the text, for example =IF(A2="Yes", 1, 0). Text comparisons in Excel are not case-sensitive, so "yes" and "YES" are treated the same.

How many IFs can you nest?

Excel allows up to 64 nested IFs, but anything beyond three or four becomes hard to read. Use IFS, a VLOOKUP against a lookup table, or the SWITCH function instead for many outcomes.

What is the difference between IF and IFS?

IF handles a single true/false test with two outcomes. IFS checks several conditions in order and returns the first one that is true, which is much cleaner than deeply nesting IFs for three or more outcomes.

How do I use IF with AND or OR?

Put AND or OR inside the logical_test, like =IF(AND(B2>=100, C2="VIP"), "Bonus", "Standard"). AND needs every condition true; OR needs at least one.

Sources and references

  1. Microsoft Support — IF function