Excel functions · Logic
IF function in Excel
IF checks whether a condition is true and returns one value if it is and another if it isn't, such as "Over budget" when actual spend is higher than budget. It's the base of most decision formulas in Excel and can be nested, or combined with AND and OR, for more than one test.
Last reviewed
Syntax
=IF(logical_test, value_if_true, [value_if_false])- logical_testrequired
- Anything that's TRUE or FALSE, such as C2>B2, A2="Paid" or AND(B2>0, C2>0).
- value_if_truerequired
- What to return when the test is TRUE: text in quotes, a number or a formula.
- value_if_falseoptional
- What to return when the test is FALSE. Left out, IF returns FALSE.
- Comparison operators: =, <>, >, <, >=, <=.
- Put text results in double quotes; numbers and cell references don't need them.
- For three or more outcomes, IFS is easier to read than nested IFs.
Which versions have IF
Every current Excel version: Microsoft 365, Excel for the web, Excel 2024, 2021, 2019 and 2016, on Windows and Mac.
| Version | Has it |
|---|---|
| Microsoft 365 (Windows and Mac) | Yes |
| Excel for the web | Yes |
| Excel 2024 | Yes |
| Excel 2021 | Yes |
| Excel 2019 | Yes |
| Excel 2016 | Yes |
Google Sheets
Google Sheets has IF with the same arguments.
Examples
The examples use this sample sheet.
| Row | A | B | C |
|---|---|---|---|
| 1 | Department | Budget | Actual |
| 2 | Marketing | 50000 | 54200 |
| 3 | Sales | 80000 | 76500 |
| 4 | IT | 60000 | 60000 |
| 5 | HR | 30000 | 27800 |
1.Flag overspending
=IF(C2>B2, "Over budget", "Within budget")Result: Over budget
Marketing spent 54,200 against a budget of 50,000.
2.Return a number
=IF(C3>B3, C3-B3, 0)Result: 0
Sales spent 76,500 of 80,000, so there's no overspend to report.
3.Nested IF for three outcomes
=IF(C4>B4, "Over", IF(C4=B4, "On budget", "Under"))Result: On budget
IT spent exactly its budget, so the second test is the one that's true.
Common errors and fixes
| Error | Why it happens | Fix |
|---|---|---|
| #NAME? | Text in the formula isn't in quotes, so Excel reads it as a name: =IF(C2>B2, Over, Under). | Quote text results: "Over". |
| FALSE in the cell | The test was false and value_if_false was left out. | Add the third argument, even if it's just "". |
| Wrong branch taken | Numbers stored as text compare as text, so "9" > "10" is TRUE. | Convert the column to numbers before comparing. |
Do it with GPTExcel
Skip writing IF by hand
Upload your Excel or CSV file to Chat and ask in plain English. GPTExcel writes the formula for your file and your version of Excel or Google Sheets.
Add a Status column that says Over, On budget or Under for each department.
Done. I used IF on your sheet and checked the results against your data.
- Written for your platform and version
- Checked against your actual data
- Newest functions looked up in official docs
IF questions
- How do I use IF with two conditions?
- Put AND or OR inside the test. =IF(AND(C2>B2, C2>50000), "Review", "OK") needs both to be true; OR needs either one.
- How many IFs can I nest in Excel?
- Excel allows up to 64 nested IF functions, but more than three or four are hard to read. Use IFS, or a lookup table with XLOOKUP, instead.
- How do I make IF return a blank cell?
- Use an empty string: =IF(C2>B2, C2-B2, ""). The cell looks empty but isn't truly blank for functions like ISBLANK.
Skip the formula hunt
Upload a spreadsheet and ask in plain English. Free plan, no credit card.
Start free