How to Use the IF Function in Excel: Examples, Nested IF and AND/OR

The Excel IF function checks one condition and returns one value if it is true and another if it is not. It is the first function most people learn and the one they keep stretching: pass or fail, late or on time, bonus or no bonus. This guide uses one six-row table you can type in a minute, and every result below was worked out by hand from that table, so you can compare your own formulas against it.

Excel IF function pass or fail results for five scores
Dan scores exactly 80, so =IF(B2>=80,”Pass”,”Fail”) returns Pass.

IF function syntax

=IF(logical_test, value_if_true, [value_if_false])

The first argument is any comparison that comes out TRUE or FALSE: B2>=80, A2="Paid", C2<>"". The second is what you want back when it is TRUE, the third when it is FALSE. Text must be in straight double quotes, numbers and cell references are not. Microsoft documents the third argument as optional, and Google Sheets calls the order of the two result arguments “the single most common source of problems with IF”.

The three arguments of the Excel IF function
The Excel IF function: a test, a value if true and an optional value if false.
광고

A worked example

Put these headers in row 1 and the six students in rows 2 to 7. Leave Eve’s Math cell (B6) completely empty, because that case matters later. Scores are real numbers, not text.

A: StudentB: MathC: English
2Ava9288
3Ben7481
4Cara5890
5Dan8079
6Eve(empty)85
7Finn10040

Start with the simplest test, typed in D2 and filled down to D7: =IF(B2>=80,"Pass","Fail"). The results are Pass, Fail, Fail, Pass, Fail, Pass. Two rows deserve a second look. Dan scores exactly 80, and >= includes the boundary, so he passes. Eve has no Math score at all, and Excel treats an empty cell as 0 in a comparison, so she fails without any warning. The blank-cell section below fixes that.

IF with AND, OR and NOT

One IF can test several things at once if you put AND or OR in the first argument. AND is TRUE only when every test is TRUE, OR is TRUE when at least one is, and NOT flips a single test.

FormulaResults for rows 2 to 7Why
=IF(AND(B2>=80,C2>=80),"Pass","Fail")Pass, Fail, Fail, Fail, Fail, FailOnly Ava (92, 88) clears both. Dan misses English by one point.
=IF(OR(B2>=90,C2>=90),"Honors","")Honors, blank, Honors, blank, blank, HonorsAva has 92 in Math, Cara has exactly 90 in English, Finn has 100 in Math.
=IF(AND(B2>=80,OR(C2>=80,B2>=95)),"Pass","Fail")Pass, Fail, Fail, Fail, Fail, PassMath must be 80 or more, plus either English 80 or more or Math 95 or more. Finn passes through the OR.
=IF(NOT(B2>=80),"Retake","")blank, Retake, Retake, blank, Retake, blankSame as B2<80; Eve’s empty cell counts as 0, so she is told to retake.

Work from the inside out when you mix them. In the third formula, Excel first evaluates the OR, then feeds that answer into the AND, then the IF picks a word. If the result looks wrong, select the OR part in the formula bar and press F9 to see what it returns on its own, then press Esc to put the formula back. AND and OR accept up to 255 tests, but a formula you cannot read at a glance will not survive the next person who opens the file.

광고

Nested IF: the order of tests matters

When there are more than two outcomes, put another IF in the “false” slot. A letter grade is the classic case: =IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F"))). For rows 2 to 7 it returns A, C, F, B, F, A. Each test runs only when every earlier one failed, which is why the later tests need just one boundary.

Nested IF in Excel: highest-first versus lowest-first test order
The same nested IF tiers give different grades depending on test order.

That is also why the order is not optional. Write the same tiers from the bottom up, =IF(B2>=70,"C",IF(B2>=80,"B",IF(B2>=90,"A","F"))), and every score of 70 or more stops at the first test. Ava (92), Dan (80) and Finn (100) all become “C”, and Excel never shows an error. Test from the highest tier down, or from the lowest up, and never mix the two directions.

Excel allows 64 levels of nested functions, far more than anyone should use. A practical limit is three or four. Past that, switch to IFS or to a lookup table.

IF, IFS or a lookup table?

=IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F") gives the same grades without the closing parentheses, but it has no built-in “otherwise”. If no test is TRUE, IFS returns #N/A, so Cara (58) would show an error if you left out the final TRUE,"F" pair. IFS exists in Excel 2019, Excel 2021, Microsoft 365 and Google Sheets, not in Excel 2016.

Excel nested IF compared with IFS and a lookup table
Nested IF, IFS and a lookup table compared for Excel grading tiers.

When the tiers change often, keep them in cells instead of in the formula. Put 0, 70, 80, 90 in G2:G5 and F, C, B, A in H2:H5. Then =VLOOKUP(B2,$G$2:$H$5,2,TRUE) returns A for Ava, C for Ben and B for Dan, and a new tier is one more row in the table, not a rewritten formula. XLOOKUP does the same with its match mode set to -1, and the older VLOOKUP needs the tier column sorted from smallest to largest.

Handling blank cells

To stop Eve from failing quietly, test for the blank first: =IF(B2="","Missing",IF(B2>=80,"Pass","Fail")). Eve’s row now says Missing and the other five rows keep their Pass and Fail. But “blank” has several meanings, and the three usual tests do not agree:

What is in the cellB6=""ISBLANK(B6)LEN(B6)=0
Nothing at allTRUETRUETRUE
A formula that returns “”TRUEFALSETRUE
One space typed by mistakeFALSEFALSEFALSE
The number 0FALSEFALSEFALSE

For data typed by people, =IF(TRIM(B2)="","Missing",...) is the safest choice because TRIM removes stray spaces first. For cells filled by other formulas, LEN(B2)=0 catches both a real blank and an empty string. Use ISBLANK only when you really mean “the cell is untouched”.

Return a calculation, not just a word

The two result arguments can hold formulas. =IF(C2>=80,AVERAGE(B2:C2),"") returns 90, 77.5, 74, blank, 85, blank for rows 2 to 7. Ben averages 74 and 81, Cara averages 58 and 90, and Eve’s average is 85 because AVERAGE ignores her empty Math cell. Dan (English 79) and Finn (English 40) fail the test and get an empty string.

To match part of a text, wrap SEARCH in ISNUMBER, because the equals sign does not accept wildcards. =IF(ISNUMBER(SEARCH("an",A2)),"Yes","No") returns Yes only for Dan. SEARCH ignores case; use FIND when case should count. For dates, compare against TODAY: =IF(D2<TODAY(),"Overdue","Open") works because dates are numbers underneath.

In Microsoft 365 one formula can test a whole range. =IF(B2:B7>=80,"Pass","Fail") typed in D2 spills six results down to D7: Pass, Fail, Fail, Pass, Fail, Pass. Keep the cells below it empty or you get #SPILL!. Excel 2019 and older need Ctrl+Shift+Enter for the same trick. In Google Sheets, wrap it as =ARRAYFORMULA(IF(B2:B7>=80,"Pass","Fail")).

Checklist before sharing an Excel IF formula
Five checks that catch most wrong IF results before you share the file.

Why your IF formula returns the wrong thing

What you seeLikely causeFix
FALSE where you wanted a blankThe third argument is missing: =IF(B2>=80,"Pass")Add ,"" or the word you want
0 instead of a blankThe argument is empty, as in =IF(B2>=80,"Pass",), or the cell you return is emptyType "" explicitly
#NAME?Text without quotes, such as =IF(B2>=80,Pass,Fail), or a misspelled functionPut the words in straight double quotes
#VALUE!A calculation inside IF uses a cell with text or an errorCheck the cells the returned formula reads
Everything passesScores are stored as text. Excel ranks any text above any number, so “5” counts as larger than 80Convert with VALUE or Text to Columns
The formula appears as textThe cell is formatted as TextFormat as General and re-enter the formula
“There’s a problem with this formula”Your regional settings use semicolonsUse =IF(B2>=80;"Pass";"Fail")

The text-versus-number problem is the sneakiest because nothing looks wrong. If Ben’s 74 was pasted in as the text “74”, =IF(B3>=80,"Pass","Fail") returns Pass. A small green triangle in the cell corner and a left-aligned number are the giveaways.

Careful: comparisons with = ignore case, so =IF(A2="ava","hit","") matches “Ava”. If case matters, use =IF(EXACT(A2,"ava"),"hit",""), which returns nothing for “Ava”.

Frequently asked questions

How do I use IF with multiple conditions in Excel?

Put AND or OR inside the first argument, for example =IF(AND(B2>=80,C2>=80),"Pass","Fail"). AND needs every test to be true, OR needs only one. For more than two outcomes, nest another IF or use IFS.

How many IF statements can you nest in Excel?

Excel allows 64 levels of nested functions, according to Microsoft’s specifications and limits page. In practice, stop at three or four levels and move the tiers into a lookup table or IFS.

Why does my IF formula return FALSE?

The test was false and you left out the third argument. Add a value, such as =IF(B2>=80,"Pass","Fail"), or use “” to show an empty cell.

What is the difference between IF and IFS?

IFS takes pairs of test and result without nesting, but it has no default result. Add TRUE as the last test to catch everything else. IFS needs Excel 2019 or later; nested IF works in every version.

How do I check whether a cell is blank in an IF formula?

Use =IF(B2="","Missing",B2). It treats an empty cell and an empty string the same way. Use TRIM(B2)="" if people may have typed a space, and ISBLANK only when the cell must be truly untouched.

Sources: Last checked November 2026. Microsoft Support: IF function, IF with AND, OR and NOT, Excel specifications and limits; Google: IF in Google Sheets; Exceljet: IFS function.

광고

#ExcelIF  #IFFunction  #ExcelFormulas  #NestedIF  #IFS  #ExcelTips  #ExcelErrors  #GoogleSheets  #ExcelGuide  #MetaTrend

Found this useful? Share it.