Excel IF Function: Syntax, Nested IF Examples and Tips

Part of the free Module 5: Excel Formulas and Functions · Function 36 of 105 · Full Excel course

The Excel IF function tests a condition and returns one value when the test is TRUE and another when it is FALSE. Use IF in Excel to label results (“Pass”/”Fail”), apply a discount only when a threshold is met, or leave a cell blank until data arrives. It is the foundation of every logical formula in Excel.

IF syntax

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

Arguments

Argument Required Meaning
logical_test Required Any expression that evaluates to TRUE or FALSE, for example A2>=50, B2=”Yes” or ISBLANK(C2).
value_if_true Optional What to return when the test is TRUE. Text must be in quotes. If omitted, IF returns 0.
value_if_false Optional What to return when the test is FALSE. If omitted, IF returns FALSE.

Comparison operators available in logical_test: = (equal), <> (not equal), >, <, >=, <=. Text comparisons are not case-sensitive.

Step-by-step example

A teacher wants “Pass” when a score in A2 is at least 50, otherwise “Fail”:

=IF(A2>=50, "Pass", "Fail")
  1. Excel evaluates A2>=50. With 63 in A2 the result is TRUE.
  2. Because the test is TRUE, IF returns the second argument, “Pass”.
  3. Copy the formula down; each row is tested independently.

Practical use cases

1. Target met or not

=IF(B2>=5000, "Target Met", "Target Not Met")

2. Calculate instead of label

=IF(E2>10, E2*0.8, E2)

Applies a 20% discount only when quantity exceeds 10.

3. Blank until data is entered

=IF(C2="", "", C2*D2)

Keeps the sheet clean while rows are still empty.

4. Multiple conditions with AND / OR

=IF(AND(A2>=50, B2="Present"), "Pass", "Fail")
=IF(OR(E2="Urgent", F2<TODAY()), "Escalate", "Normal")

5. Nested IF for grades

=IF(A2>=90, "A", IF(A2>=75, "B", IF(A2>=60, "C", "D")))

Excel allows up to 64 nested levels, but beyond three or four the formula becomes hard to read. In Excel 2019 and 365, IFS does the same job without nesting: =IFS(A2>=90,"A",A2>=75,"B",A2>=60,"C",TRUE,"D").

6. Data validation with ISNUMBER

=IF(ISNUMBER(D2), "Number", "Not a Number")

Common mistakes and errors

  • #NAME? – text without quotes, for example =IF(A2>50, Pass, Fail). Wrap text in double quotes.
  • #VALUE! – comparing a number with text, or a logical_test that returns text instead of TRUE/FALSE.
  • Result shows FALSE – value_if_false was omitted. Supply the third argument, even if it is “”.
  • Numbers stored as text – “50” is not equal to 50. Convert with VALUE or Text to Columns.
  • Unbalanced parentheses in nested IFs – each IF needs its own closing bracket. Excel colours matching brackets as you type; check the last one.
  • Testing for errors with IF – IF(A2=#N/A,…) does not work. Use IFERROR or ISERROR.

Tips and best practices

  • Write the test as a question with a Yes/No answer before building the formula; if you cannot phrase it, you probably need two IFs or a lookup table.
  • Return numbers, not text, when the result feeds calculations. “Yes”/”No” in a column blocks SUM; 1/0 keeps everything numeric.
  • Use Alt+Enter inside the formula bar to break long nested IFs onto separate lines; Excel ignores the line breaks and the logic becomes readable.
  • Evaluate Formula (Formulas tab) steps through each branch and shows which test returned TRUE, the fastest way to debug an unexpected result.
  • Replace repeated nesting with IFS, SWITCH or an approximate-match VLOOKUP once you pass three conditions.

Related functions

Frequently asked questions

Can the IF function compare text?

Yes. Use =IF(A2=”Yes”, 1, 0). The comparison is not case-sensitive, so “yes” and “YES” both match. For a case-sensitive test wrap the comparison in EXACT.

What happens if I leave value_if_false blank?

If you omit the third argument completely, Excel returns the logical value FALSE. To show an empty cell instead, pass two double quotes: “”.

How many IF functions can be nested?

Excel 2007 and later allow 64 nested IF levels. For more than three conditions, IFS, SWITCH or a lookup table are easier to read and maintain.

Need a ready-made template? Browse 7,000+ Excel, Power BI and Google Sheets templates at NextGenTemplates.com.