IF Function in Excel
The IF function returns one value when a condition is true and another when it's false. Learn the syntax, combine it with AND and nest it for grades, then practice.
- Free, no sign-up
- No upload – files stay on your device
- Phone, tablet and computer
The IF function in Excel makes a decision: if a condition is true, it returns one value, otherwise another. Passed or failed, discount or no discount, “late” or “on time” all come down to one IF formula. In the practice sheet above, you grade a course step by step, from a simple test to a nested IF with four grades.
How the IF function in Excel works
The syntax is =IF(logical_test, value_if_true, value_if_false).
- logical_test is a comparison that is either TRUE or FALSE, for example
B2>=60. - value_if_true is returned when the test is true, for example
"pass". - value_if_false is returned otherwise, for example
"fail".
So =IF(B2>=60,"pass","fail") shows “pass” for 94 points and “fail” for 55 points. Text goes in quotation marks; numbers and cell references don’t.
| Operator | Meaning | Example |
|---|---|---|
= |
equal to | D2="pass" |
<> |
not equal to | D2<>"pass" |
> / < |
greater / less than | B2>90 |
>= / <= |
greater / less than or equal to | C2>=80% |
Practice right here
The sheet above shows ten course participants with their score and attendance. The rules are in row 13. Type a formula into the first green cell of a column, copy it down with the fill handle and click Check:
- Show “pass” or “fail” (60 points or more passes).
- Return a $50 refund for everyone who passed.
- Combine IF with AND: a certificate needs a pass and at least 80% attendance.
- Grade with a nested IF: excellent, good, satisfactory or fail.
The check points out typical slip-ups, such as > instead of >= for someone with exactly 60 points.
Several conditions: AND and OR
IF tests one condition. To test several, put AND or OR inside the test:
=IF(AND(B2>=60,C2>=80%),"yes","no")returns “yes” only if both conditions are met.=IF(OR(B2>=90,C2=100%),"award","")returns “award” if at least one condition is met.
Nested IF and IFS
For more than two outcomes, put another IF in place of value_if_false. Test from the highest tier down:
=IF(B2>=90,"excellent",IF(B2>=75,"good",IF(B2>=60,"satisfactory","fail")))
Every IF needs its own closing parenthesis, which is why there are three at the end. IFS is shorter: =IFS(B2>=90,"excellent",B2>=75,"good",B2>=60,"satisfactory",TRUE,"fail"). The final TRUE catches everything else.
Common mistakes
- Text without quotation marks:
=IF(B2>=60,pass,fail)returns #NAME?. Write"pass". - Numbers in quotation marks:
"50"is text and can’t be added up. Write50. - > instead of >=: “at least 60” includes 60 itself.
- Wrong order in a nested IF: if you test
>=60first, everyone above 60 is “satisfactory” and the higher tiers never get a chance. - Missing parentheses: count the opening and closing parentheses in nested formulas.
IF also works well together with other functions. To add up only matching values, SUMIF is often simpler than IF, and COUNTIF counts them. For long tier tables, a VLOOKUP with an approximate match is easier to maintain than many nested IFs.
Frequently asked questions
Where do I find the IF function in Excel?
Type it straight into the cell, or go to Formulas → Logical. In the Spreadsheet Editor, it’s in the logical category under Formulas.
Can IF return an empty cell?
Yes, use two quotation marks: =IF(B2>=60,"pass",""). The cell then looks empty.
How many IFs can I nest?
Current Excel versions allow up to 64. In practice, more than three or four become hard to read; IFS or a lookup table is the better choice then.
Can I use IF with dates?
Yes. For example, =IF(A2<TODAY(),"overdue","") marks every date before today.
Microsoft Excel is a trademark of Microsoft Corporation. The Spreadsheet Editor is not affiliated with Microsoft.