How to use IF in Excel
IF checks a condition and returns one value when it's true and another when it's false. It's the foundation of decision-making in spreadsheets: pass/fail, bonus/no bonus, overdue/on time.
Syntax
=IF(logical_test, value_if_true, value_if_false)
logical_test | A condition, e.g. B2>=60, A2="Yes", C2<>"". |
value_if_true | What to return when the condition is TRUE. |
value_if_false | What to return when it's FALSE (optional — FALSE if omitted). |
Examples
=IF(B2>=60, "Pass", "Fail")Grade a test.=IF(C2>B2, "Over budget", "OK")Compare actual vs. budget.=IF(B2>10000, B2*5%, 0)Bonus only above a sales target.=IF(A2="", "", B2*C2)Calculate only when the row is filled in.IF with AND and OR: several conditions
IF tests one condition, but that condition can combine several: AND needs all of them to be true, OR needs at least one.
=IF(AND(B2>=50000, C2>=90%), "Bonus", "")A bonus only when sales are at least 50,000 and at least 90% of the target is met.=IF(OR(D2="VIP", B2>100000), "Priority", "Standard")Priority for VIP clients or for big orders.Nested IF: three or more outcomes
Put an IF inside another IF to choose between several results. Excel checks the tests from left to right and stops at the first TRUE, so start with the highest threshold. From Excel 2019, IFS does the same without the brackets piling up.
=IF(B2>=90, "A", IF(B2>=75, "B", IF(B2>=60, "C", "Fail")))A grade from a score.=IFS(B2>=90, "A", B2>=75, "B", B2>=60, "C", TRUE, "Fail")The same with IFS.Check for blanks and for words inside a cell
Compare with an empty string "" to test for blanks. To check whether a cell contains a word anywhere, combine SEARCH and ISNUMBER.
=IF(C2="", "Missing", "OK")Flags the rows where C2 is empty.=IF(ISNUMBER(SEARCH("refund", B2)), "Refund", "")Marks the rows whose description mentions a refund.Common mistakes
- Text without quotes
=IF(B2>60, Pass, Fail)gives #NAME?. Text must be in double quotes:"Pass".- Many nested IFs
- IF inside IF inside IF quickly becomes unreadable. Use
IFSor a lookup table instead. - Comparing text that looks the same
"Yes "with a trailing space isn't equal to"Yes". Clean the data with TRIM.
Frequently asked questions
How many IFs can you nest in Excel?
Up to 64, but anything beyond three or four is hard to read and easy to break. Use IFS, SWITCH or a lookup table with XLOOKUP instead.
Why does my IF formula return #NAME?
The text in the formula has no double quotes. =IF(B2>50, Pass, Fail) makes Excel look for something called Pass. Write "Pass" and "Fail".
Why does IF return FALSE?
The third argument, value_if_false, is missing. =IF(B2>50, "Pass") returns FALSE when the test fails. Add "" as the third argument to show a blank instead.
Can IF return a calculation instead of text?
Yes. Each result can be a number, a cell or a whole formula: =IF(B2>10000, B2*5%, 0) pays 5% commission only on sales above 10,000.
Available in: All versions of Excel, Excel for the web, Google Sheets