Home › Excel functions › IF
IF Function in Excel: How to Write an IF Formula
An IF statement in Excel checks whether a condition is true and returns one value if it is and another if it isn't. It's the foundation of decision-making in Excel: pass or fail, bonus or no bonus, late or on time.
In this guide
IF syntax
=IF(logical_test, value_if_true, [value_if_false])| Argument | What it means |
|---|---|
| logical_test | A comparison that is either TRUE or FALSE, such as B2>=60. |
| value_if_true | What to return when the test is TRUE. |
| value_if_false (optional) | What to return when the test is FALSE. If you leave it out, Excel returns the word FALSE. |
Basic example: pass or fail
Students need a score of at least 60 to pass.
| A | B | C | |
|---|---|---|---|
| 1 | Student | Score | Result |
| 2 | Anna | 72 | Pass |
| 3 | Ben | 55 | Fail |
| 4 | Chris | 90 | Pass |
| 5 | Dana | 60 | Pass |
Enter this in C2 and copy it down. Anna scored 72, which is 60 or more, so she gets Pass. Ben's 55 is lower, so he gets Fail. Dana's exactly 60 also passes, because >= means "greater than or equal to".
Text goes between double quotes. Numbers, cell references and TRUE/FALSE don't. =IF(B2>=60, Pass, Fail) without quotes returns #NAME?.
IF practice: try it yourself
Reading is one thing, typing it is another. Build the formula below step by step: the tips tell you what to type next, and you can click or drag across cells to add them, just like in Excel.
Task: Show "Pass" in C2 if the score is 60 or more, otherwise "Fail": =IF(B2>=60,"Pass","Fail")
Comparison operators
| Operator | Meaning | Example |
|---|---|---|
= | Equal to | =IF(A2="Paid", "✓", "") |
<> | Not equal to | =IF(A2<>"", "Filled", "Empty") |
> | Greater than | =IF(B2>100, "Large", "Small") |
< | Less than | =IF(C2<TODAY(), "Overdue", "") |
>= | Greater than or equal to | =IF(B2>=60, "Pass", "Fail") |
<= | Less than or equal to | =IF(B2<=0, "Out of stock", "In stock") |
Text comparisons are not case-sensitive: "paid" and "PAID" are treated as equal.
Return a calculation instead of text
The values to return can be formulas too. A 5% bonus on sales over 10,000, and nothing otherwise:
Comparison operators: what to type
| Type | Means |
|---|---|
| = | is equal to |
| > | greater than |
| < | less than |
| >= | greater than or equal to: first >, then = |
| <= | less than or equal to: first <, then = |
| <> | not equal to: first <, then > |
Always two separate keys, never a special symbol.
To leave a cell visually empty instead of showing 0, return an empty string: =IF(B2>10000, B2*5%, "").
IF with AND and OR
To check several conditions at once, put AND or OR inside the logical test.
- AND: all conditions must be true.
=IF(AND(B2>=60, C2="Yes"), "Pass", "Fail")passes only students who scored 60+ and handed in their assignment. - OR: at least one condition must be true.
=IF(OR(B2="VIP", C2>1000), "Free shipping", "")gives free shipping to VIP customers or large orders.
AND and OR together in one IF
Sometimes one condition must always be true, while the other may be any of several options. Then you put OR inside AND. A bonus for sales over 10,000, but only in the North or South region:
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Rep | Sales | Region | Bonus |
| 2 | Anna | 12,000 | North | Bonus |
| 3 | Ben | 15,000 | West | |
| 4 | Chris | 8,000 | South |
Anna meets both parts and gets Bonus. Ben sold enough but works in the West, so the OR part is FALSE. Chris is in the South but stays under 10,000. Read the formula from the inside out: OR first gives TRUE or FALSE, then AND checks that result together with the sales test.
It works the other way round too: =IF(OR(AND(B2>10000, C2="North"), B2>20000), "Bonus", "") gives a bonus for more than 10,000 in the North, or for more than 20,000 in any region.
Nested IFs: more than two outcomes
When there are more than two possible results, you can put an IF inside another IF. This assigns grades A to F:
=IF(B2>=80, "A", IF(B2>=70, "B", IF(B2>=60, "C", IF(B2>=50, "D", "F"))))Excel checks the conditions from left to right and stops at the first one that's true. Order matters: always start with the highest threshold. A score of 72 fails the first test, passes the second, and returns B.
Simpler: the IFS function
In Excel 2019, 2021, 2024 and Microsoft 365 you can use IFS, which lists condition/result pairs without the nesting:
=IFS(B2>=80, "A", B2>=70, "B", B2>=60, "C", B2>=50, "D", TRUE, "F")The final TRUE, "F" acts as "everything else". For long lists of thresholds, a lookup table with XLOOKUP or VLOOKUP is often easier to maintain than either.
IF with text
Text in an IF formula always goes between double quotes, in the test and in the result: =IF(B2="Paid", "Done", "Send reminder"). Three things to know:
- IF ignores upper and lower case: "paid" and "PAID" also match.
- To check whether a cell contains a word, combine IF with SEARCH:
=IF(ISNUMBER(SEARCH("paid", B2)), "Yes", "No"). - To check whether a cell is empty, compare with two quotes:
=IF(B2="", "Missing", B2).
Case-sensitive tests and wildcards in IF
A normal comparison ignores case, so =IF(A2="abc", …) also matches ABC. For an exact match that includes capitals, use EXACT:
Wildcards such as * and ? don't work with the = sign either: =IF(A2="*paid*", "Yes", "No") only matches a cell that literally says *paid*. COUNTIF does understand wildcards, so use it as the test:
COUNTIF returns 1 when A2 contains "paid" anywhere and 0 when it doesn't, and IF treats every number except 0 as TRUE. More patterns are on the COUNTIF page.
Common IF mistakes
- #NAME?: text without quotes, or a misspelled function name.
- The cell shows FALSE: you left out
value_if_false. Add""to show nothing. - Wrong result with numbers: the numbers may be stored as text.
"100">50doesn't behave like100>50. Convert them with VALUE or Text to Columns. - Nested IF gives the wrong grade: the conditions are in the wrong order. Test the highest threshold first.
- Too many parentheses to keep track of: switch to IFS or a lookup table.
More IF examples
Copy a formula and change the ranges to match your own data.
| What you want | Formula |
|---|---|
| Only calculate when A2 is filled in | =IF(A2="", "", B2*C2) |
| 1 if A2 contains the text in E1, otherwise 0 | =IF(ISNUMBER(SEARCH(E1, A2)), 1, 0) |
| Mark a date in the past | =IF(B2<TODAY(), "x", "") |
| 10% bonus only when B2 is between 10 and 20 | =IF(AND(B2>=10, B2<=20), B2*0.1, 0) |
| How much B2 is above target C2 (never negative) | =IF(B2>C2, B2-C2, 0) |
Keep learning
Frequently asked questions
Is there an IF THEN ELSE in Excel?
Yes, that is exactly what IF does: =IF(condition, then, else). For example =IF(B2>=50, "Pass", "Fail") means: if B2 is 50 or more, then "Pass", else "Fail". There is no separate ELSE or THEN keyword.
How many IFs can you nest in Excel?
Up to 64 levels. In practice, more than three or four makes a formula hard to read; use IFS or a lookup table instead.
How do I make IF return a blank cell?
Use an empty string as the result: =IF(A2>10, "Yes", ""). The cell looks empty, although technically it contains text of zero length.
Can IF check if a cell contains certain text?
Yes, combine it with ISNUMBER and SEARCH: =IF(ISNUMBER(SEARCH("urgent", A2)), "Priority", "") returns Priority when A2 contains the word urgent anywhere.
What's the difference between IF and IFS?
IF tests one condition with two outcomes; you nest several IFs for more outcomes. IFS tests multiple conditions in one flat list and returns the result for the first one that's true.
How do I use IF with dates?
Compare with a date function, not with a date in quotes: =IF(B2<TODAY(), "x", "") or =IF(B2>=DATE(2026, 1, 1), 1, 0). A date typed between quotes is treated as text, so the comparison gives wrong results.
How do I check if a cell is empty with IF?
Use =IF(A2="", "empty", "filled") or =IF(ISBLANK(A2), "empty", "filled"). The first also treats a formula that returns "" as empty; ISBLANK only sees truly empty cells.
Can an IF formula change the colour of a cell?
No, a formula can only return a value, not formatting. Use the same test as a rule in conditional formatting: Home › Conditional Formatting › New Rule › Use a formula to determine which cells to format, with for example =$B2>=60.
How do I compare two cells with IF?
=IF(A2=B2, "Same", "Different"). This ignores upper and lower case; for a case-sensitive check use =IF(EXACT(A2, B2), "Same", "Different").
Why does my IF formula return 0?
One of the results is left empty, as in =IF(B2>10, , "Low"): for that case Excel shows 0. Put "" or a text there. A reference to an empty cell gives 0 as well: =IF(A2="x", B2, "") shows 0 when B2 is empty.