Excel IF Function: Multiple Conditions, Nested IF and Fixes When It Fails

The Excel IF function checks a condition and returns one result when it is true and another when it is false. It is the base of almost every decision in a spreadsheet: pass or fail, paid or overdue, bonus or no bonus. This guide covers the syntax, working examples with text, numbers and blanks, how to use IF with multiple conditions using AND and OR, nested IF and its modern alternatives, and why an IF formula stops working.

IF function syntax

The formula is =IF(logical_test, value_if_true, value_if_false). The logical test is any comparison that Excel can judge as TRUE or FALSE, such as B2>=50 or A2="Paid". The second part is what Excel shows when the test is true, and the third is what it shows when the test is false. Text results go inside quotation marks, numbers and cell references do not.

Suppose column B holds exam scores. In C2 type =IF(B2>=50,"Pass","Fail") and fill the formula down. Every row now shows Pass or Fail depending on its own score. Change a score and the result changes immediately, which is the whole point: you describe the rule once and Excel applies it everywhere.

Examples with numbers, text and blanks

GoalFormulaResult
Pass or fail at 50=IF(B2>=50,"Pass","Fail")Pass when B2 is 50 or more
Text match=IF(A2="Paid","Done","Chase")Done when A2 says Paid
Check for a blank cell=IF(A2="","Missing","OK")Missing when A2 is empty
Calculate a bonus=IF(B2>10000,B2*0.05,0)5 percent bonus above 10,000
Leave the cell empty=IF(B2>0,B2*2,"")Shows nothing when B2 is zero or less

Two details save time. Text comparisons ignore upper and lower case, so "paid" and "Paid" match. And an empty string, written as two quotation marks with nothing between them, makes a formula cell look blank. Be careful with it, because a cell that holds an empty string is not truly empty and some later formulas will treat it as text.

IF with multiple conditions: AND and OR

To require two things at once, wrap the tests in AND: =IF(AND(B2>=50,C2>=50),"Pass","Fail") passes only when both scores reach 50. To accept either one, use OR: =IF(OR(B2>=50,C2>=50),"Pass","Fail") passes when at least one does. You can put several tests inside AND or OR, separated by commas, and you can combine the two, for example =IF(AND(B2>=50,OR(C2="Yes",D2="Yes")),"Eligible","Not eligible").

Nested IF and better alternatives

A nested IF puts one IF inside another to handle more than two outcomes. For grades: =IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F"))). Excel reads the tests from left to right and stops at the first one that is true, so the order matters: always go from the strictest condition to the loosest. If you reverse the order, a score of 95 would match the first test it meets and return the wrong grade.

Nested IF becomes hard to read after three or four levels. Newer versions of Excel offer IFS, which lists the pairs in a row: =IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F"). For lookups against a table of ranges, a lookup function is cleaner still; see our comparison of XLOOKUP and VLOOKUP.

IF with dates and TODAY

Dates are numbers in Excel, so IF compares them like any other value. To flag overdue invoices, put the due date in column C and use =IF(C2=TODAY(),C2<=TODAY()+7),"Due soon","Later"). The TODAY function updates every time the file opens, so the status stays current without any editing. If a date came from another system as text, the comparison will not work; convert it with DATEVALUE first, or retype one cell to see whether Excel recognizes it as a date.

You can also combine IF with other functions to avoid errors. Wrapping a division in IF stops the #DIV/0! message: =IF(C2=0,"",B2/C2) shows nothing when the divisor is zero. IFERROR is shorter for the same purpose, but IF lets you decide exactly which condition you are guarding against, which keeps real mistakes from being hidden.

Why your IF formula is not working

ProblemLikely causeFix
Formula shows as textCell formatted as Text, or a leading apostropheSet format to General and re-enter
Always returns FALSE or the false valueNumbers stored as textConvert with Text to Columns or VALUE
#NAME? errorTypo in the function or missing quotation marks around textCheck spelling and quotes
Wrong result in a nested IFConditions in the wrong orderPut the strictest test first
Result not updatingCalculation set to manualFormulas tab, Calculation Options, Automatic

When the result looks wrong, test the logical part alone in another cell, for example =B2>=50. If that shows TRUE or FALSE correctly, the problem is in the results; if not, the problem is in the data or the comparison.

Where to go next

IF pairs naturally with counting and summing. Read the SUMIF guide to add numbers that meet a condition, and use IF rules to drive conditional formatting. The basics are in our 15 Excel formulas for beginners. If you want a guided path, a structured course helps (Udemy Excel courses, affiliate link: we earn a commission if you buy through it, at no extra cost to you).

Frequently asked questions

How many IF functions can I nest? Modern Excel allows 64 levels, but anything past three or four is a sign to switch to IFS or a lookup.

Can IF return a formula? Yes. The true and false parts can be calculations, such as B2*0.05.

Does IF work in Google Sheets? Yes, with the same syntax, and IFS exists there too.

How do I test for text that contains a word? Combine IF with ISNUMBER and SEARCH: =IF(ISNUMBER(SEARCH("late",A2)),"Check","OK").

Summary

Write the test, then the true result, then the false result. Use AND when every condition must hold, OR when one is enough, and put the strictest test first in a nested IF. Switch to IFS or a lookup when the formula grows long. Practice on a score sheet with Pass or Fail, then a grade column, and test the logical part alone whenever a result surprises you.

Related guides: How to Remove Duplicates in Excel: 4 Safe Methods and Fixes When It Finds None, Excel SUMIF Function: Syntax, 5 Examples and Fixes for Wrong Totals, Excel Conditional Formatting: Highlight Duplicates, Overdue Rows and More (With Formulas).

Get new guides by email
One short email when a new guide is published. No spam, and you can leave anytime.

Comments

Popular posts from this blog

Excel Formulas for Beginners: 15 Formulas With Examples You Will Use Every Week

Two-Factor Authentication: A 30-Minute Setup That Actually Holds

Excel COUNTIF Function: Syntax, Wildcards and 8 Examples