The IF function in Excel returns one value when a condition is TRUE and another when it is FALSE, written as =IF(logical_test, value_if_true, value_if_false). This is the core of conditional logic in spreadsheets, letting you automate decisions like flagging overdue invoices or grading test scores.
What the IF Function Actually Does
IF evaluates a single condition you supply, such as A2>100 or B2="Paid". If that condition is true, it returns the second argument; if false, it returns the third. The condition can compare numbers, text, dates, or even other formulas. For example, with sales in B2:B10, =IF(B2>=500, "Bonus", "No Bonus") in C2 labels each row. The function only ever returns one of the two values you provide—it cannot return a blank cell unless you explicitly put "" (empty text) as the value.
Nested IFs and Their Limits
When you need more than two outcomes, you can nest IF functions inside each other: =IF(A1>=90,"A",IF(A1>=80,"B",IF(A1>=70,"C","F"))). This works but becomes hard to read beyond a few levels. Excel allows up to 64 nested IFs, but practically you should stop around 3–4 and switch to IFS or a lookup table. The IFS function, available in Excel 2019 and Microsoft 365, is cleaner: =IFS(A1>=90,"A",A1>=80,"B",A1>=70,"C",TRUE,"F"). Note that IFS stops at the first true condition, so order matters. For multiple unrelated conditions, consider using AND, OR, or NOT inside a single IF: =IF(AND(A1>0,B1<0),"Mixed","Same sign").
Common Errors and How to Fix Them
The most frequent mistake is mismatched parentheses or using text without quotes. If you write =IF(A1>10, Yes, No), Excel treats Yes and No as named ranges and returns #NAME?. Always quote text: "Yes". Another classic is the #VALUE! error when comparing numbers stored as text—use VALUE() or ensure the cells are numeric. A third issue is the missing FALSE argument: =IF(A1>10,"High") returns FALSE when the condition is not met, which can be confusing. Provide an explicit third argument, even if it is "" or 0. Also, beware of trailing spaces in text comparisons; use TRIM() inside the condition if needed.
Using IF with Other Functions
IF pairs naturally with SUMIF, COUNTIF, and AVERAGEIF for conditional aggregation, but you can also embed IF inside SUMPRODUCT for complex criteria. For example, =SUMPRODUCT((A2:A100="East")*(B2:B100)) sums sales for East without using IF. More directly, you can use IF with VLOOKUP to handle missing values: =IF(ISNA(VLOOKUP(D2,A:B,2,FALSE)),"Not found",VLOOKUP(D2,A:B,2,FALSE)). The modern replacement is IFERROR: =IFERROR(VLOOKUP(D2,A:B,2,FALSE),"Not found"), which is shorter and catches all error types. For array formulas, IF can return arrays—for instance, =SUM(IF(A2:A10>5,B2:B10)) entered with Ctrl+Shift+Enter in older Excel, but in Microsoft 365 it works as a dynamic array without special entry.
How to Choose Between IF, IFS, and SWITCH
Use IF for a single binary decision or when you need to combine conditions with AND/OR. Use IFS when you have a chain of mutually exclusive thresholds (like grades) and you want readable code. Use SWITCH when you are matching an exact value against a list: =SWITCH(A1,1,"One",2,"Two","Other"). SWITCH is simpler than nested IFs for exact matches but does not handle ranges. Also consider using a lookup table with VLOOKUP or XLOOKUP for many categories—it is easier to maintain than editing formulas. For example, a tax bracket table with thresholds and rates is far clearer than a 10-level nested IF. In general, if your logic has more than 4–5 branches, a lookup table or IFS is better.
IF in Conditional Formatting and Data Validation
You can use IF directly in conditional formatting rules. Select a range, go to Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format. Enter a formula like =IF($A1>100,TRUE,FALSE) or simply =$A1>100—the IF is optional because the rule already evaluates true/false. This is useful for highlighting entire rows based on a column value. For data validation, you can restrict input with an IF-based formula: select the cell, Data > Data Validation > Custom, and enter =IF($A$1="Yes",B2>0,TRUE) to require a positive number only when A1 says Yes. Remember that conditional formatting formulas must be relative to the active cell in the selection, so adjust the row references accordingly.
Performance and Best Practices
IF functions are fast, but thousands of nested IFs or array IFs can slow down large workbooks. Keep formulas simple and avoid volatile functions like TODAY() inside IF unless necessary. Use helper columns to break complex logic into steps—this makes auditing easier. Also, prefer boolean arithmetic: instead of =IF(A1>10,1,0), use =(A1>10)*1 which returns 1 or 0. For counting with multiple conditions, COUNTIFS is more efficient than an array of IFs. Finally, document your logic with comments (Insert > Comment) or a legend, because a long IF formula is hard to decipher months later. Consider using named ranges for conditions, like =IF(Sales>Target,"Hit","Miss") where Sales and Target are named ranges—this improves readability.
Frequently Asked Questions
Can IF return a blank cell? Yes, use "" as the value_if_true or value_if_false. For example, =IF(A1="","",A1*2) leaves the cell blank if A1 is blank. Note that this returns an empty text string, not a truly empty cell, which can affect formulas that check for blanks.
Why does my IF formula show TRUE or FALSE instead of my values? You likely forgot to provide the value_if_false argument, or you used a comparison that returns a boolean. For instance, =IF(A1>10) is invalid—you need three arguments. Also, if you wrote =IF(A1>10,"High") without the third argument, it shows FALSE when the condition is not met.
How do I use IF with dates? Dates are stored as numbers, so comparisons work directly. For example, =IF(A1>TODAY(),"Future","Past") checks if a date is after today. Be careful with date formatting—ensure the cells contain real dates, not text, otherwise the comparison may be alphabetical.
Is IF case-sensitive? No, IF is not case-sensitive by default. =IF(A1="apple","Yes","No") will match "Apple" as well. If you need case-sensitive matching, use EXACT inside IF: =IF(EXACT(A1,"apple"),"Yes","No").
What is the difference between IF and IFERROR? IF checks a condition you define; IFERROR checks whether a formula results in an error (like #N/A or #DIV/0!). Use IFERROR to handle errors gracefully, such as =IFERROR(1/A1,"Cannot divide"). They are not interchangeable—IFERROR only catches errors, not false conditions.
Can I use IF in Google Sheets the same way? Yes, the syntax is identical. However, Google Sheets also has IFS and SWITCH, and it supports array formulas with ARRAYFORMULA. The main difference is that in Excel, you might need Ctrl+Shift+Enter for array IFs, while Sheets handles them automatically when wrapped in ARRAYFORMULA.
Related
- Data Entry Software Programs: Types & Picks
- Project Slab Pond Table: Build & Design Guide
- How to Make Random Numbers in C++
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Python split() Function: How It Works with ExamplesThe split() method in Python divides a string into a list of substrings based on a specified separator,…
- LAMBDA in Excel: A Practical Guide to Custom FunctionsYes—Excel’s LAMBDA function lets you create reusable custom functions without writing VBA. For a quick test, with no…
- Excel How to Count Unique Values: 4 Easy WaysTo count unique values in Excel, use =SUMPRODUCT(1/COUNTIF(range, range)) for a quick total, or =COUNTA(UNIQUE(range)) if you have…
- Copy a Number in Excel Without Copying the FormulaTo copy a formula cell’s displayed number without copying its formula, copy the cell, select where it should…
- How to Filter in Excel Without a Mouse: Keyboard GuideTo filter a list in Excel for Microsoft 365 on Windows without a mouse, select a cell in…
- Excel Sum Whole Column: Formulas, Examples, and TipsTo sum every numeric value in an Excel column, enter =SUM(A:A) in a cell outside column A and…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.