SQLExcelHTML & CSSTouch typingBlogChoose a course
Lurndo › Blog › Excel
  1. Short answer
  2. What does the IF function do in Excel?
  3. How do you write an IF statement in Excel?
  4. How does IF work on a real sheet?
  5. Which comparisons can you use in an IF test?
  6. How do you use IF with AND and OR?
  7. How do you nest IF functions for more than two outcomes?
  8. What's the difference between IF and IFERROR?
  9. Why isn't my IF formula working?
  10. Which functions are related to IF?
  11. Frequently asked questions

Excel IF function examples: text, AND, OR, nested IF and IFS

One test, two outcomes and a handful of traps. On a swimming pool's members sheet you'll see IF at work, from a simple choice to three categories, and you'll try it yourself right away.

C

Christophe, founder of Lurndo
November 5, 2026 · 12 min read

The IF function lets a cell choose: if the test is TRUE, it shows the second argument, otherwise the third, as in =IF(B2<12,"child","adult"). Text goes in quotation marks, numbers don't. AND and OR let you test several conditions at once, and for more than two outcomes you nest one IF inside another or use IFS. Leave out the last argument and a test that fails shows FALSE.

Exercise: right in your browser, on real data

Practise this: the lesson on IF, free

Sources: 13 sources you can check

A paper path of blank spreadsheet cells that splits in two at a small signpost with blank arrow boards, one branch ending in a green cell and the other in a warm yellow cell, on light green paper.

What does the IF function do in Excel?

IF lets a formula choose between two outcomes. You give it a test: if the test is true, the cell shows one thing, and if it isn't, the other. =IF(B2<12,"child","adult") shows child for anyone under 12 and adult for everyone else. Microsoft calls IF "one of the most popular functions in Excel" on its own help page (Microsoft).

Want to learn it step by step, with the explanation right on the sheet? Follow the lesson Choosing with IF. Below you'll find the syntax, an example for every kind of test, IF with AND and OR, more than two outcomes and the mistakes that come up most, all on the same sheet.

How do you write an IF statement in Excel?

An IF formula has three arguments, separated by commas: the test, what the cell shows when the test is TRUE, and what it shows when the test is FALSE. Only the last one is optional (Microsoft).

=IF(logical_test,value_if_true,[value_if_false])
ArgumentWhat you put inExample
logical_testA comparison that gives TRUE or FALSEB2<12
value_if_trueWhat the cell shows when the test is true"child"
value_if_falseWhat the cell shows when the test isn't true. Leave it out and the cell shows FALSE"adult"

Source: the FALSE isn't on IF's regular help page, but it is in Microsoft's description of the function for developers (Microsoft Learn).

The test is almost always a comparison: B2<12 asks whether B2 is less than 12, C2="Single" whether C2 says Single. A result can be text, a number, a reference or a calculation. Text goes in quotation marks (Microsoft), numbers don't. Type the comma but nothing after it, as in =IF(B2<12,"child",), and you get 0 instead of FALSE.

The comma between the arguments isn't fixed, by the way. Which separator Excel uses depends on your operating system's locale and your Excel settings, and the comma and the semicolon are the most common (Microsoft). That's why a colleague in Belgium or the Netherlands writes =IF(B2<12;"child";"adult"), or in Dutch Excel =ALS(B2<12;"kind";"volwassene").

How does IF work on a real sheet?

You type the formula once in the first row and fill it down. IF then decides again for every row, using that row's values. Take the members sheet of The Splash swimming pool in Tamworth, the third client in our Excel course. Children under 12 get the summer pass at half price, and Dave at the front desk wants to see for each member whether they're a child.

RowA: NameB: AgeC: PassD: VisitsE: Paid (£)F: Category
2Jack9Single315child
3Nora34Annual22240adult
4Mila15Monthly925adult
5Rita67Annual15240adult
6Laura41Single10adult
7Rory7Monthly625child
8Jim72Annual18240adult
9Will28Single420adult
10Hannah12 (as text)Monthly1125adult
11Sara55Annual0240adult

Row 1 holds the column headers. Laura's visits are empty and Hannah's age was typed as text, both on purpose: you'll see why further down.

F2 holds =IF(B2<12,"child","adult"). Jack is 9, the test is TRUE, so F2 shows child. Fill the formula down to F11 and B2 moves along to B3, B4 and so on, so IF looks at the age on its own row each time. Only Jack and Rory are under 12. Rita and Jim are seniors, but they get adult too: this formula only knows two outcomes.

Now try it yourself, on the real sheet of The Splash. This time you test text rather than a number, and the result is an amount.

Try it: what does each member pay at the desk?

A single swim costs £5 at the desk, and pass holders pay nothing. In H2, put what Jack pays at the desk and fill down to H11.

ABCDEFGHI
1NameAgePassVisitsPaidCategoryPer visit
2Jack9Single3£15.00
3Nora34Annual22£240.00
4Mila15Monthly9£25.00
5Rita67Annual15£240.00
6Laura41Single£10.00
7Rory7Monthly6£25.00
8Jim72Annual18£240.00
9Will28Single4£20.00
10Hannah12Monthly11£25.00
11Sara55Annual0£240.00
12
H2

Your formula ran in your own browser, and then we checked it again on a second, hidden version of the sheet with other passes. Type the amounts in by hand and it works here but gets caught there.

Which comparisons can you use in an IF test?

Six: equal to, not equal to, less than, greater than, and the last two with "or equal to" added. Every comparison gives TRUE or FALSE (Microsoft), and that's exactly what IF needs as its first argument. Here's each operator on The Splash's sheet:

OperatorMeaningTestTRUE for
=equal toC2="Single"Jack, Laura and Will
<>not equal toC2<>"Annual"everyone without an annual pass
<less thanB2<12Jack and Rory
>greater thanD2>15Nora and Jim
<=less than or equal toE2<=20Jack, Laura and Will
>=greater than or equal toD2>=15Nora, Rita and Jim

Watch the boundary. D2>15 and D2>=15 only differ for someone who came exactly 15 times, and that's Rita. If the rule says "from 15 visits", she's in, and you write >=. Not sure? Say the rule out loud for that one row. You can practise comparisons on their own in the lesson Comparing.

How do you test for text?

Text goes in quotation marks in the test, just like in the result. Case doesn't matter: =IF(C2="single",5,0) gives Jack 5 as well, even though his cell says Single with a capital S. If case has to count, put EXACT inside the test, a function Microsoft describes as case-sensitive (Microsoft). An extra space does count, though, as you'll see in the mistakes below.

Can the result of IF be a calculation?

Yes. A result can be a number, a reference or a whole calculation. Say children only pay half of the amount in column E:

=IF(B2<12,E2/2,E2)

That gives £7.50 for Jack and £12.50 for Rory, and everyone else keeps the amount from column E. Don't put quotation marks around the calculation: "E2/2" is text, and the cell would literally show E2/2 instead of an amount.

How do you leave a cell blank with IF?

With two quotation marks and nothing in between. According to Microsoft, "" essentially means "nothing" (Microsoft). The first formula below only shows something for members who came 10 times or more:

=IF(D2>=10,"frequent","")
=IF(D2="","unknown",D2)

Nora, Rita, Jim and Hannah get frequent, and the others a cell that looks empty. The other way round, "" tests whether a cell is empty. The second formula shows unknown for Laura, whose visits nobody filled in, and the number otherwise. Sara gets 0: her cell isn't empty, it holds a 0.

How do you use IF with AND and OR?

You put AND or OR inside the test of IF. AND returns TRUE when every condition holds, OR when at least one does, and IF then picks its result (Microsoft). On The Splash's second sheet, Dave keeps track of the swimming badges as TRUE or FALSE. You can only go in the deep end with badge A and badge B. Say one badge is enough for the club gala:

=IF(AND(C2,D2),"deep","shallow")
=IF(OR(C2,D2),"can enter","not yet")
RowA: ChildC: Badge AD: Badge BWith ANDWith OR
2EllaTRUEFALSEshallowcan enter
3IliasTRUETRUEdeepcan enter
4ZoëFALSEFALSEshallownot yet
5BenTRUETRUEdeepcan enter
6AmiraTRUEFALSEshallowcan enter
7TheoTRUETRUEdeepcan enter
8NinaFALSEFALSEshallownot yet
9SonnyTRUETRUEdeepcan enter

With AND, four children may go in the deep end: Ilias, Ben, Theo and Sonny, who have both badges. With OR, six can enter the gala, because Ella and Amira have badge A, and that's enough. Since C and D already hold TRUE or FALSE, there's nothing left to compare. On the members sheet you just write the comparisons as arguments: AND(C2="Annual",D2>=20) is only true for Nora.

Two things often go wrong. The conditions go inside the function as arguments: IF(C2 AND D2,…) isn't something Excel understands. And pick the right one: =AND(A2="Ella",A2="Ben") is always FALSE, because one cell can't hold two names at once. If you mean "Ella and Ben", you mean OR. You'll practise NOT, which flips a test, along with these two in the lesson AND, OR and NOT.

How do you nest IF functions for more than two outcomes?

Put a second IF where the third argument goes. If the first test fails, Excel works out the second IF, and that gives you three outcomes. The summer pass gets three prices: one for children, one for seniors from 65 and one for everyone else. Both formulas below give every member their category:

=IF(B2<12,"child",IF(B2>=65,"senior","adult"))
=IFS(B2<12,"child",B2>=65,"senior",TRUE,"adult")

Nested IF: an IF inside an IF. Each IF closes its own bracket, so count them.

Jack and Rory become child, Rita and Jim senior, and the others adult, with one exception: Hannah becomes senior, although she's 12. That's down to the age stored as text, and the next section explains it.

IFS lists the tests one after another, each followed by its result, and Microsoft says it's "much easier to read" (Microsoft). If no test is true, it returns #N/A. That's why the last test is TRUE, which always holds: it's your default result. IFS works from Office 2019 on and with Microsoft 365. If someone opens your file in an older Excel, stick with the nested IF.

With a nested IF and with IFS, the first test that's true wins. So put the strictest test first.

You'll build both in the lesson More than two choices.

What's the difference between IF and IFERROR?

IF tests a condition you choose. IFERROR only checks whether a formula returns an error value, and shows something else if it does (Microsoft). Dave wants to know what each member pays per visit: the amount divided by the number of visits. For Sara, who hasn't been yet, and for Laura, whose visits are empty, that division returns #DIV/0!.

=IF(D2=0,"-",E2/D2)
=IFERROR(E2/D2,"-")

On this sheet they give the same: £5 per visit for Jack, £16 for Rita, and a dash for Laura and Sara. The difference is in what they catch. IF catches exactly the case you test. IFERROR catches every error value, including the #NAME? from a typo in your own formula, which you then no longer see. So only wrap it around a formula that works, as you'll practise in the lesson Catching error values.

Why isn't my IF formula working?

Usually because of one of these six things. You'll spot the first one straight away by its error value. The others return a result that looks believable, and those are the dangerous ones.

Text without quotation marks gives #NAME?

=IF(B2<12,child,adult) shows #NAME? on every row. Without quotation marks, Excel reads child as a name, looks for it and can't find it (Microsoft). Put every piece of text in quotation marks. A typo in the function name gives the same error.

A number stored as text

Hannah's age was typed as text, and you'll often spot a cell like that by its left alignment and a small green triangle. =IF(B10>=65,"senior","regular") returns senior for her: Excel doesn't compare the text "12" as the number 12. With B10<12 she got adult, but that was right by accident. Numbers stored as text can cause unexpected results, and you fix them with Convert to Number or the VALUE function (Microsoft).

One space too many

If C2 says "Single " with a trailing space, C2="Single" returns FALSE: to Excel that's different text. You can't see the space, and it easily slips in with data you copy from somewhere else. TRIM removes all spaces except single spaces between words (Microsoft), so with =IF(TRIM(C2)="Single",5,0) the test works again.

The order of nested IFs

Excel runs through the tests and stops at the first one that's true. In =IF(B2>=12,"adult",IF(B2>=65,"senior","child")), Rita and Jim become adult: 67 and 72 are 12 or more too, so the second test never gets a turn. In Microsoft's own example, revenue of $12,500 gets the lowest commission this way (Microsoft). Put the strictest test first.

Semicolons in a formula from a European colleague

Copy =ALS(B2<12;"kind";"volwassene") from a Dutch forum and you have two things to change in English Excel: ALS becomes IF, and the semicolons become commas. Which separator your Excel expects depends on the locale (Microsoft), not on the language. With English Excel and Belgian settings, it's =IF(B2<12;"child";"adult"): English names, but semicolons.

Too many nested IFs

Excel lets you nest up to 64 IF functions, but Microsoft itself says it's "not at all advisable" (Microsoft): a formula like that is hard to build correctly and hard to maintain. With many outcomes, choose IFS, or put the thresholds in a table and look them up with VLOOKUP, as Microsoft suggests.

Which functions are related to IF?

IF decides between two outcomes, cell by cell. For anything beyond that, Excel has functions from the same family. If you work with colleagues in Belgium or the Netherlands, the Dutch names are handy too:

FunctionIn Dutch ExcelWhen to use it
IFSALS.VOORWAARDENMore than two outcomes, with the tests in a row
AND, OR, NOTEN, OF, NIETSeveral conditions in one test
IFERRORALS.FOUTReplacing an error value with something readable
SWITCHSCHAKELENComparing one value with a list of possible values
COUNTIFAANTAL.ALSCounting the cells that meet a condition
SUMIFSOM.ALSAdding up what meets a condition

SWITCH fits when you compare one cell with a fixed list. =SWITCH(C2,"Single",5,"Monthly",2,0) gives 5 for a single swim, 2 for a monthly pass and 0 for the rest. The last argument is the default; without it, SWITCH returns #N/A when nothing matches (Microsoft). Like IFS, it works from Office 2019 on and with Microsoft 365.

If you want one total instead of a result per member, you don't need IF at all. =COUNTIF(B2:B11,"<12") counts the children: 2. =SUMIF(C2:C11,"Annual",E2:E11) adds up what the annual pass holders paid: £960. You'll find more examples in COUNTIF explained and SUMIF with examples.

The formulas you'll need most are in 12 basic Excel formulas everyone should know, and every function with its Dutch name is on the Excel cheat sheet. IF sticks best when you type it yourself: in module 3 of our Excel course for beginners you do that at The Splash, with exercises we check on their result.

Frequently asked questions

How do I use IF with multiple conditions in Excel?

If every condition has to be true, put AND inside the test, as in =IF(AND(C2,D2),"deep","shallow"). If one is enough, use OR. For more than two outcomes, put a second IF where the third argument goes, or use IFS, which lists the tests one after another and takes the first one that's true.

What does IF return if you leave out the last argument?

When the test is false, the cell shows FALSE. =IF(B2<12,"child") gives child for the children and FALSE for everyone else. Type the comma but nothing after it and you get 0 instead. If you want a cell that looks empty, give it two quotation marks: =IF(B2<12,"child","").

Why does my IF formula show #NAME?

Usually there's text without quotation marks in it, such as child instead of "child". Excel reads it as a name, looks for it and can't find it. A typo in the function name gives the same error. So put every piece of text in quotation marks, and leave numbers without them.

How many IF statements can you nest in Excel?

Excel accepts up to 64 nested IF functions in one formula, but Microsoft itself says that's "not at all advisable": a formula like that is hard to build correctly and harder still to maintain. From three or four outcomes on, IFS is clearer, and a long list of thresholds belongs in a table you look up.

Is the IF function case-sensitive?

No. A comparison with = ignores case, so =IF(C2="single",5,0) also matches Single and SINGLE. Spaces do count, though: "Single " with a trailing space is different text to Excel. If case has to matter, put EXACT inside the test, as in =IF(EXACT(C2,"Single"),5,0).

Practise this in the course

Every lesson explains first and then lets you practise yourself, with a real spreadsheet in your browser.

  • IFLogic · Choosing with IF
  • IFSLogic · More than two choices
  • AND and ORLogic · AND, OR and NOT
  • IFERRORLogic · Catching error values
Start Excel for free

Sources

  1. Microsoft Support, IF function
  2. Microsoft Support, IF function – nested formulas and avoiding pitfalls
  3. Microsoft Support, IFS function
  4. Microsoft Learn, Excel.Functions class
  5. Microsoft Support, Calculation operators and precedence in Excel
  6. Microsoft Support, EXACT function
  7. Microsoft Support, Using IF to check if a cell is blank
  8. Microsoft Support, Using IF with AND, OR, and NOT functions in Excel
  9. Microsoft Support, IFERROR function
  10. Microsoft Support, How to avoid broken formulas in Excel
  11. Microsoft Support, Convert numbers stored as text to numbers in Excel
  12. Microsoft Support, TRIM function
  13. Microsoft Support, SWITCH function
C

Christophe, founder of Lurndo

Christophe builds Lurndo from Belgium, with short, playful exercises for SQL, Excel, HTML & CSS and touch typing that show straight away what your answer does. On this blog, Christophe answers the questions people run into while learning, with sources you can check yourself.

Read next

  • How to calculate an average in Excel: blanks, zeros, conditions and weighted averagesIt's one function, yet averages go wrong all the time. See how AVERAGE works, what it skips, and how to average without zeros, with a condition or with weights, on real spreadsheets.Excel · November 5, 2026 · 11 min read
  • COUNTIF examples: how to count text, numbers, blanks and duplicates in ExcelOne function, two arguments, and it still miscounts more often than you'd think. On a charity shop's sheet you'll see every kind of criterion at work, and you'll type the formula yourself.Excel · November 5, 2026 · 12 min read

SQL

  • Topics
  • All lessons
  • Cheat sheet
  • Sandbox

Excel

  • Topics
  • All lessons
  • Cheat sheet
  • Shortcuts

HTML & CSS

  • Topics
  • All lessons
  • Cheat sheet

Touch typing

  • Topics
  • All lessons
  • Cheat sheet
  • Typing test

Lurndo

  • Dashboard
  • Leaderboard
  • Premium
  • Account
  • Blog
  • FAQ
  • Contact & support
  • Privacy
Nederlands