What IF does
IF checks whether a condition is true, then returns one value if it is and another if it isn’t. =IF(B2>=80,"Pass","Retake") shows Pass for a score of 80 or more and Retake for anything lower. You’ll also hear it called an IF statement or an if-then formula.
The test is a comparison, such as whether a number is over a limit or a cell says “Paid”. Each result can be text, a number or a calculation of its own, so IF can label rows or work out a charge only when it applies.
Because the formula refers to cells, the answer changes on its own when the data does. Change a score from 74 to 81 and “Retake” turns into “Pass”.
Syntax
logical_testRequired- A comparison that is either TRUE or FALSE, such as
B2>=80orC2="Paid". You can compare with=,<>,>,<,>=and<=. value_if_trueOptional- What the cell shows when the test is TRUE: text in quotation marks (
"Pass"), a number, a cell or a whole calculation. value_if_falseOptional- What the cell shows when the test is FALSE. Leave it out and the cell shows the word FALSE, which is rarely what you want.
Example: pass or retake
A safety quiz needs 80 points to pass. The formula in C2 is filled down to C6.
>=, at least 80. In C2, =IF(B2>=80,"Pass","Retake") returns Pass.Read it as: if B2 is at least 80, show “Pass”, otherwise show “Retake”. Filled down, each row tests its own score: C3 checks B3, C4 checks B4.
Example: pay overtime only when it’s earned
In this US team, hours over 40 a week are paid at one and a half times the hourly rate. Anyone who works 40 hours or fewer gets 0 overtime.
Here the result for TRUE is a calculation, and Excel works it out only when the test passes.
Practice this in ProExcel
Mark who gets a bonus with IF, in a real practice sheet.
Checking your answers needs a free account.
IF with multiple conditions
An IF has a single test, but that test can combine several conditions, and an IF can sit inside another when there are more than two outcomes.
- When every condition must hold, put AND inside the test:
=IF(AND(B2>=10,B2<=20),"In range","Out of range")checks whether B2 is between 10 and 20. - When any one condition is enough, use OR:
=IF(OR(C2="Urgent",D2>30),"Call today","")flags a ticket marked Urgent or open for more than 30 days. - For three or more results, nest one IF inside another and test the highest band first:
=IF(B2>=90,"A",IF(B2>=80,"B","C")). In Excel 2019 and later, IFS writes the same as a list of tests:=IFS(B2>=90,"A",B2>=80,"B",TRUE,"C").
You can practice AND and OR inside IF in the free lesson Combine tests with AND, OR and NOT.
Common mistakes
=IF(B2>=80,Pass,Retake)shows#NAME?, because Excel looks for something named Pass. Text results always go in quotation marks."0"in quotation marks is text, so a column of IF results written that way won’t add up with SUM. Write0.- A limit typed into the formula means editing every formula when the limit changes. Put 80 in a cell of its own and refer to it with a locked reference such as
$F$1. - With bands such as 90, 80 and 70, test the highest one first.
=IF(B2>=70,"C",IF(B2>=80,"B","A"))gives C to a score of 95, because the first test already passes. =IF(B2>=80 AND C2="Yes",…)isn’t valid. Combine the tests with AND or OR:=IF(AND(B2>=80,C2="Yes"),…).
Frequently asked questions
How do I use IF with multiple conditions?
Put AND or OR inside the test. =IF(AND(B2>=80,C2="Yes"),"Pass","Retake") needs both conditions to be true, while OR needs only one. For three or more outcomes, nest one IF inside another or use IFS.
Can IF leave a cell blank?
Yes. Use two quotation marks with nothing between them as the result: =IF(B2>40,B2-40,""). The cell looks empty, though it still holds a formula.
Why is my IF formula returning FALSE?
The cell shows the word FALSE when the test fails and the formula has no third argument, as in =IF(B2>=80,"Pass"). Add the value to show instead, even "" for a blank. If the test looks true but you still get the false result, look for a trailing space or a number stored as text, which makes C2="Paid" or B2=80 false.
How do I check if a cell contains certain text?
IF can’t use wildcards in a comparison, so test with SEARCH inside ISNUMBER: =IF(ISNUMBER(SEARCH("late",B2)),"Follow up","") shows Follow up when the word late appears anywhere in B2, in any capitals.
How many IFs can I nest?
Excel allows 64 IF functions inside one another, but a formula with more than three or four gets hard to check. For bands, IFS (Excel 2019 and later) or a lookup table is easier to read.
Is IF case-sensitive when it compares text?
No. =IF(C2="paid",…) matches “Paid” and “PAID” as well. Use EXACT inside the test when capitals matter.