The IF function in Excel checks whether a condition is true or false and returns one value if true and another if false. The syntax is =IF(logical_test, value_if_true, value_if_false). For example, =IF(A1>10, "Over", "OK") returns "Over" when A1 is greater than 10 and "OK" otherwise. This guide walks through writing, nesting, and troubleshooting IF formulas in Excel for Microsoft 365, Excel 2021, 2019, and 2016 on Windows and Mac. Menu labels and function names can differ slightly by version and region, but the IF function itself is consistent across desktop and mobile apps.

What You'll Need

  • Excel installed on your computer or the Excel mobile app (the desktop version is easier for formula editing).
  • A worksheet with data in cells, or a blank sheet to practice.
  • Basic familiarity with cell references like A1 and B2.
  • For text results, quotation marks around the text values.

Step-by-Step

  1. Select the cell for the result. Click an empty cell where you want the IF result to appear, for example C2 next to a row of data.
  2. Start the formula. Type =IF( and Excel will show a tooltip with the arguments: logical_test, value_if_true, value_if_false.
  3. Write the logical test. This is a comparison that evaluates to TRUE or FALSE. Examples: A2>=60, B2="Yes", C2<>"" (not blank). Use comparison operators: =, >, <, >=, <=, <>. Text values go in double quotes; numbers do not.
  4. Add a comma and the value if true. For example, "Pass" or a number like 100 or a cell reference like D2. Text must be in quotes; numbers and cell references are not.
  5. Add a comma and the value if false. For example, "Fail" or 0. If you omit this argument, Excel returns FALSE when the test is false; to return a blank, use "".
  6. Close the parenthesis and press Enter. The formula should look like =IF(A2>=60, "Pass", "Fail"). Excel displays the result and the formula remains in the formula bar.
  7. Copy the formula down. Drag the fill handle (the small square at the bottom-right of the cell) down the column. Relative references adjust automatically, so A2 becomes A3, and so on.
  8. Test edge cases. Change a value to see the result switch. Check that text comparisons match exactly (Excel is not case-sensitive for text in IF, but extra spaces matter).
  9. Nest IFs for multiple conditions (optional). Put another IF in the value_if_false position: =IF(A2>=90, "A", IF(A2>=80, "B", IF(A2>=70, "C", "F"))). Excel allows up to 64 nested IFs, but keep it readable. For many categories, consider the IFS function in newer Excel versions or a lookup table.
  10. Combine with AND/OR (optional). Use =IF(AND(A2>=60, B2="Yes"), "Pass", "Fail") to require both conditions, or OR for either. AND/OR go inside the logical_test argument.
  11. Handle errors (optional). Wrap the formula in IFERROR to replace errors with a friendly value: =IFERROR(IF(A2/B2>1, "High", "Low"), "Check data"). This hides #DIV/0! and similar errors.
  12. Verify results. Use Formulas > Evaluate Formula (desktop) to step through the calculation, or temporarily change inputs to confirm both branches work.

Common Mistakes

  • Missing quotes around text. =IF(A1=Yes, 1, 0) returns #NAME? because Yes is treated as a name. Use "Yes".
  • Unbalanced parentheses. Each IF needs one closing parenthesis. Excel colors parentheses to help; count them if you get an error.
  • Using = for “equals” inside text. In the logical test, = is correct for comparison, but text values still need quotes: A1="Yes".
  • Forgetting the false argument. Omitting it returns FALSE, which looks like an error to some users. Use "" for blank.
  • Nesting too deeply. Long nested IFs are hard to audit. Use IFS or a lookup table for many conditions.
  • Comparing numbers stored as text. A number formatted as text may not compare as expected. Use VALUE() or clean the data.
  • Absolute vs relative references. When copying, use $A$1 if a reference must stay fixed.

Tips

  • Use named ranges (Formulas > Define Name) to make formulas readable, e.g., =IF(Score>=60, "Pass", "Fail").
  • Press Alt+Enter (Windows) or Option+Return (Mac) to add line breaks inside a formula for readability.
  • Use the Formula Bar’s function tooltip: click the function name and press Ctrl+A (Windows) or Command+A (Mac) to open the Function Arguments dialog.
  • For case-sensitive text comparison, use EXACT: =IF(EXACT(A1, "Yes"), 1, 0).
  • Test with a small sample before filling down a large column.
  • Keep the logical test simple; move complex calculations to helper cells.

Troubleshooting

  • #NAME? error: Usually unquoted text or a misspelled function. Check quotes and spelling.
  • #VALUE! error: A text value is used where a number is expected, or a cell reference is wrong. Check data types.
  • Formula shows as text: The cell is formatted as Text. Change format to General, then re-enter the formula (press F2, then Enter).
  • Wrong result: Use Evaluate Formula to see which branch is taken. Check for extra spaces with TRIM, and confirm comparison operators.
  • Circular reference warning: The formula refers to its own cell. Move the formula or adjust references.
  • Fill handle not copying correctly: Check relative/absolute references; use $ where needed.
  • Mobile app limitations: The Excel mobile app supports IF but editing long nested formulas is easier on desktop.

Frequently Asked Questions

Can IF return a blank cell?

Yes. Use "" as the value_if_true or value_if_false, e.g., =IF(A1="", "", "Filled"). The cell looks blank but contains an empty string.

How many conditions can I nest?

Excel allows up to 64 nested IF functions, but for readability and performance, use IFS (available in Excel 2019 and Microsoft 365) or a lookup table when you have more than three or four conditions.

Is IF case-sensitive?

No. IF’s text comparisons are not case-sensitive. For case-sensitive checks, use the EXACT function inside IF.

Can I use IF with dates?

Yes. Compare dates with >, <, etc., e.g., =IF(A1>DATE(2025,1,1), "New", "Old"). Ensure dates are stored as dates, not text.

Why does my IF formula return FALSE instead of my value?

You likely omitted the value_if_false argument. Add a comma and a value, or use "" for blank.

Does IF work in Excel for the web and mobile?

Yes, the IF function works in Excel for the web and the Excel mobile app. The formula syntax is the same, though editing is easier on a desktop.