Lesson 15 of 92 · Free Excel Course
Excel
Excel IF Formula: Make Excel Decide (Plus IFS, AND, OR and IFERROR)
Learn the Excel IF formula step by step: text vs number results, blanks, nested IF, IFS, AND/OR inside IF and IFERROR, with a grades example.
So far every formula in this course has done the same thing every time: add these, multiply that. The IF function is different. It looks at a cell, asks a yes-or-no question, and shows one answer or another depending on what it finds. That's how a spreadsheet marks a test score as Pass or Fail, flags an overdue bill or works out who gets a bonus. This lesson covers how IF is built, how to chain several tests together, the newer IFS function that makes long chains easier, and how to combine IF with AND, OR and IFERROR. You'll finish by turning scores into letter grades two different ways and getting the same answer both times.
How the IF formula works
IF takes three pieces of information, separated by commas:
=IF(logical_test, value_if_true, value_if_false)
- logical_test is the question. It must come out as TRUE or FALSE, for example
B2>=60("is B2 at least 60?"). - value_if_true is what the cell shows when the answer is TRUE.
- value_if_false is what it shows when the answer is FALSE. Microsoft lists this one as optional, but leave it out and a failed test shows FALSE or 0, which is rarely what you want. Always fill it in.
A plain-English way to read it: "IF this is true, show this, otherwise show that."
The test almost always uses a comparison operator. These are the six Excel understands:
| Operator | Means | Example test |
|---|---|---|
= | equal to | C2="East" |
> | greater than | B2>100 |
< | less than | B2<0 |
>= | greater than or equal to | B2>=60 |
<= | less than or equal to | B2<=10 |
<> | not equal to | C2<>"Paid" |
Each one gives TRUE or FALSE, and IF uses that to choose. Notice that "at least 60" is >=, not >. Picking the wrong one is the most common reason a score of exactly 60 lands in the wrong group.
Your first IF formula: Pass or Fail
Here's a short list of test scores. A score of 60 or more passes. On Windows:
- Click C2.
- Type
=IF(B2>=60,"Pass","Fail"). As you type=IF(, Excel shows a small tip with the three argument names, and the one you're on is in bold. - Press Enter. Ann's 92 shows Pass.
- Click C2 again and double-click the small square at its bottom-right corner (the fill handle) to copy the formula down to C9. Each row now tests its own score, because B2 becomes B3, B4 and so on, as explained in absolute and relative references.
On a Mac, press Return instead of Enter; everything else is the same. In Excel for the web the steps are identical.
| A | B | C | |
|---|---|---|---|
| 1 | Name | Score | Pass/Fail |
| 2 | Ann | 92 | Pass |
| 3 | Ben | 78 | Pass |
| 4 | Cara | 85 | Pass |
| 5 | Dev | 59 | Fail |
| 6 | Eli | 70 | Pass |
| 7 | Fay | 64 | Pass |
| 8 | Gus | 100 | Pass |
| 9 | Hana | 45 | Fail |
Text, numbers and blank results
The two results can be text, numbers, cell references or even other formulas. The rules for writing them:
- Text goes in double quotes.
"Pass"works;Passwithout quotes gives a#NAME?error, because Excel thinks you mean a function or a named range. - Numbers don't need quotes.
=IF(C2="Yes",1,2)returns real numbers you can add up later. If you write"1"in quotes you get text that only looks like a number, and SUM will skip it. - TRUE and FALSE don't need quotes either. Excel recognises them as logical values.
- Calculations work too.
=IF(B2>100,B2*10%,0)gives a 10% bonus on anything over 100 and zero otherwise. - A blank result is two quotes with nothing between them:
"".=IF(B2>100,"Over","")writes "Over" for big numbers and leaves the rest looking empty.
That last trick keeps a sheet tidy, but remember the "empty" cell still contains a formula. It isn't truly blank, which matters later for things like counting blanks.
Nested IF: more than two answers
One IF gives you two possible results. For letter grades you need five: A (90+), B (80+), C (70+), D (60+) and F. The answer is to put another IF where the "false" result goes, so that when one test fails, the next one runs. This is called a nested IF.
- Click D2.
- Type
=IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C",IF(B2>=60,"D","F")))). - Press Enter and copy it down to D9.
Read it from the left. Is the score 90 or more? Then "A". If not, is it 80 or more? Then "B". And so on, until anything left over gets "F". There are four IFs, so the formula ends with four closing brackets. Excel colours each matching pair of brackets as you type, which helps you count them.
Order matters. Tests are checked left to right and the first TRUE one wins. If you started with B2>=60, Ann's 92 would pass that first test and get a "D" before Excel ever reached the A test. Always go from the highest threshold down (or the lowest up, using <).
Excel lets you nest up to 64 IFs in one formula. Microsoft's own advice is not to come anywhere near that. Beyond two or three levels, nested IFs get hard to read, hard to check and easy to break with one misplaced bracket. When you have many bands, use IFS, below, or a lookup table (covered in VLOOKUP and HLOOKUP).
IFS: many tests without the nesting
IFS does the same job as a chain of nested IFs, but you list the tests and results in pairs instead of putting functions inside functions:
=IFS(test1, result1, test2, result2, ...)
IFS checks each test in order and returns the result for the first one that is TRUE. You can have up to 127 pairs. The same grades in column E:
- Click E2.
- Type
=IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",B2>=60,"D",TRUE,"F"). - Press Enter and copy it down to E9.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Name | Score | Pass/Fail | Grade (nested IF) | Grade (IFS) |
| 2 | Ann | 92 | Pass | A | A |
| 3 | Ben | 78 | Pass | C | C |
| 4 | Cara | 85 | Pass | B | B |
| 5 | Dev | 59 | Fail | F | F |
| 6 | Eli | 70 | Pass | C | C |
| 7 | Fay | 64 | Pass | D | D |
| 8 | Gus | 100 | Pass | A | A |
| 9 | Hana | 45 | Fail | F | F |
Look at the last pair, TRUE,"F". IFS has no "otherwise" slot of its own. If none of the tests is TRUE, it returns the #N/A error. Hana's 45 fails all four score tests, so without that last pair she'd get #N/A instead of F. Writing TRUE as the final test works as a catch-all: TRUE is always true, so anything that reaches it gets the default result.
Which versions have IFS? Excel for Microsoft 365 on Windows and Mac, Excel for the web, and Excel 2019, 2021 and 2024. Excel 2016 and older don't know the function, so the cell usually shows #NAME?. If you share files with people on old versions, stick with nested IF.
AND, OR and NOT inside IF
Sometimes one question isn't enough. A sales rep gets a bonus only if they sold at least $5,000 and have been with the company for two years or more. Put the AND function in the test:
=IF(AND(B12>=5000,D12>=2),"Yes","No")
- AND is TRUE only when every condition inside it is true.
- OR is TRUE when at least one condition is true.
- NOT flips a single condition:
NOT(C12="East")is TRUE for every region except East.
AND and OR accept up to 255 conditions, though two or three is plenty for a readable formula. Here's the bonus check alongside an OR test that flags anyone with sales below $3,000 or less than a year in the job, using a blank "" for everyone else:
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 11 | Rep | Sales | Region | Years | Bonus? (AND) | Check (OR) |
| 12 | Kim | $6,200 | East | 3 | Yes | |
| 13 | Leo | $2,800 | West | 4 | No | Check |
| 14 | Mia | $5,100 | West | 0 | No | Check |
| 15 | Ned | $9,000 | East | 2 | Yes |
Ned has exactly 2 years, and D15>=2 includes 2, so he qualifies. Leo has the years but not the sales, so he doesn't.
IFERROR: replace an error with something friendlier
Errors such as #DIV/0! (dividing by zero) or #N/A look alarming on a finished sheet. IFERROR checks a formula and, if it produces any error, shows your chosen value instead:
=IFERROR(B19/C19,"No units")
If the division works, you see the normal answer. If C19 is 0, you see "No units" instead of #DIV/0!. In the practice workbook, Boxes cost $120 for 4 units, giving 30, and Labels give 3, while Tape has 0 units, so IFERROR shows the message. IFERROR catches every error type, including #N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME? and #NULL!.
Use it carefully. Because it hides every error, it can also hide a real mistake, like a typo in a formula. Add IFERROR once a formula is working, not to make a broken one look fine.
Try it yourself
Download the practice workbook and open the Practice sheet. Yellow cells are where you type.
- In C2, type
=IF(B2>=60,"Pass","Fail")and copy it down to C9. Dev and Hana should show Fail. - In D2, type the nested IF
=IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C",IF(B2>=60,"D","F"))))and copy it down. Ann gets A, Ben C. - In E2, type
=IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",B2>=60,"D",TRUE,"F")and copy it down. Column E should match column D exactly. - Delete
,TRUE,"F"from Hana's IFS formula and watch it turn into #N/A. Undo with Ctrl+Z (Cmd+Z on a Mac). - In E12, type
=IF(AND(B12>=5000,D12>=2),"Yes","No")and copy it down to E15. Kim and Ned get Yes. - In F12, type
=IF(OR(B12<3000,D12<1),"Check","")and copy it down. Leo and Mia show Check. - In E18, type
=IFERROR(B18/C18,"No units")and copy it down to E20. Tape shows No units.
Compare your results with the Answers sheet.
Common mistakes
- Forgetting quotes around text.
=IF(B2>=60,Pass,Fail)gives #NAME?. Text results need"Pass". - Putting numbers in quotes.
"10"is text, so totals and averages ignore it. Leave numbers bare. - Using
>when you mean>=. A score of exactly 60 failsB2>60. Decide whether the boundary number is in or out. - Testing thresholds in the wrong order. In a nested IF or IFS, the first TRUE test wins. Start with the highest band.
- No catch-all in IFS. Without
TRUE,"something"at the end, anything that matches no test shows #N/A. - Miscounting brackets. Each nested IF needs its own closing bracket at the end. Excel's coloured brackets help you match them.
- Typing
"TRUE"in quotes. That's the word TRUE as text, not the logical value. As the last IFS test it causes a #VALUE! error. - Wrapping everything in IFERROR. It hides real problems as well as expected ones.
What's next
IF lets one cell make a decision. Next, COUNTIF, SUMIF and AVERAGEIF use the same kind of test across a whole column, so you can count or total only the rows that match. If you'd like a refresher first, go back to absolute and relative references, see the full Excel course, or keep the Excel shortcuts cheat sheet handy while you practise. Later pages cover the SWITCH function and Excel errors and fixes.
Frequently asked questions
How do I write an IF formula in Excel?
Type =IF( then three parts separated by commas: the test, what to show if it's true, and what to show if it's false. For example =IF(B2>=60,"Pass","Fail") shows Pass when B2 is 60 or more and Fail otherwise. Put text results in double quotes; numbers don't need them.
How many IF functions can you nest in Excel?
Excel allows up to 64 IF functions inside one formula, but Microsoft itself advises against going that deep. Past two or three levels the formula gets hard to read and easy to break. Use IFS or a lookup table instead (see VLOOKUP and HLOOKUP).
What is the difference between IF and IFS?
IF runs one test and picks one of two results. IFS runs a list of tests in order and returns the result for the first one that is TRUE, so it replaces a chain of nested IFs. IFS needs Excel 2019 or later, Microsoft 365 (Windows or Mac) or Excel for the web.
Why does my IFS formula return #N/A?
None of the tests was TRUE, so IFS had nothing to return. Add TRUE as the last test with a default result, for example ...,B2>=60,"D",TRUE,"F"). TRUE always passes, so it catches everything left over.
How do I make an IF formula show a blank cell?
Use two double quotes with nothing between them as the result: =IF(B2>100,"Over",""). The cell looks empty, although it still holds a formula. Don't leave the argument out completely, or Excel may show 0 instead.
How do I use IF with two conditions?
Put AND or OR inside the test. =IF(AND(B2>=5000,D2>=2),"Yes","No") needs both conditions to be true. =IF(OR(B2<3000,D2<1),"Check","") needs only one of them.