IF Statements in Excel: How to Write and Use Them

Formulas & functions · Updated November 22, 2026

The IF function in Excel performs a logical test and returns one value if the test is TRUE and another if it is FALSE. Its syntax is =IF(logical_test, value_if_true, value_if_false) — for example, =IF(A1>10,"High","Low") returns “High” when A1 is greater than 10, otherwise “Low”.

What the IF Function Does

IF is one of Excel’s most used functions because it lets you build decision-making into your worksheets. You give it a condition (like a cell being empty, a number exceeding a target, or a date being past due) and it outputs one result when the condition is true and a different result when it is false. The condition can compare numbers, text, dates, or even other formulas. For instance, =IF(B2="Paid","OK","Pending") checks if cell B2 contains the exact text “Paid” and returns “OK” if it does, or “Pending” if it doesn’t.

The function returns exactly what you put in the true and false arguments — numbers, text (in quotes), cell references, or even other formulas. You can also leave an argument blank (e.g., =IF(C2>0,C2,"")) to show nothing when the condition is false.

How to Write an IF Statement (Step by Step)

  1. Select the cell where you want the result.
  2. Type =IF( — Excel will show a tooltip with the three arguments.
  3. Enter the logical test. For example, D2>=50 checks if D2 is 50 or more.
  4. Type a comma, then the value if true (e.g., "Pass").
  5. Type another comma, then the value if false (e.g., "Fail").
  6. Close the parenthesis and press Enter: =IF(D2>=50,"Pass","Fail").

You can also use the Function Arguments dialog: go to Formulas > Insert Function, search for IF, and fill in the three fields. The dialog shows a live preview of the result, which helps when you’re learning.

Using Comparison Operators in the Logical Test

The logical test can use any of Excel’s comparison operators:

  • = equal to (e.g., A1="Yes")
  • > greater than (e.g., B1>100)
  • < less than (e.g., C1<0)
  • >= greater than or equal to
  • <= less than or equal to
  • <> not equal to (e.g., D1<>"Closed")

You can also combine conditions with AND or OR inside the IF. For example, =IF(AND(A1>0,B1>0),"Both positive","Not both") returns “Both positive” only if both A1 and B1 are greater than zero. The OR function works similarly — it returns TRUE if any condition is true.

Nested IFs and the IFS Alternative

When you need more than two outcomes, you can nest IF functions inside each other. For example, to assign a letter grade: =IF(A1>=90,"A",IF(A1>=80,"B",IF(A1>=70,"C","F"))). This works but gets hard to read with many levels. Excel 2016 and later (including Microsoft 365) offer the IFS function, which is cleaner: =IFS(A1>=90,"A",A1>=80,"B",A1>=70,"C",TRUE,"F"). IFS checks conditions in order and returns the value for the first TRUE one. The final TRUE acts as a catch-all for anything else. For Excel 2013 and earlier, you must use nested IFs.

Common Errors and How to Fix Them

  • #NAME? — Usually means you misspelled the function name or forgot quotes around text. Write IF not if, and put text in double quotes like “High”.
  • #VALUE! — Often happens when you compare text without quotes or use a cell with an error. Check that your logical test is valid.
  • Wrong results (e.g., returning FALSE) — If you omit the value_if_false argument, IF returns the word FALSE when the condition is not met. Always include both arguments unless you intentionally want FALSE.
  • Too many nested IFs — Older Excel versions limit nesting to 64 levels, but that’s rarely practical. Use IFS or a lookup table instead.
  • Text case sensitivity — IF is not case-sensitive; IF(A1="yes",...) matches “Yes”, “YES”, and “yes”. If you need case-sensitive matching, use EXACT inside the test: IF(EXACT(A1,"Yes"),...).

Using IF with Other Functions (Real Examples)

IF becomes powerful when combined with other functions. Here are two common patterns:

1. IF with SUM to check a total. With sales in B2:B10, =IF(SUM(B2:B10)>1000,"Target met","Below target") returns “Target met” if the sum exceeds 1000.

2. IF with ISBLANK to handle empty cells. =IF(ISBLANK(A1),"No entry",A1*2) shows “No entry” if A1 is empty, otherwise it doubles the value in A1.

You can also use IF to avoid division by zero. With quantity in A1 and price in B1, =IF(A1=0,0,B1/A1) returns 0 if A1 is zero, otherwise it computes the unit price. This prevents the #DIV/0! error.

IF vs. Other Lookup and Logic Functions

IF is not always the best tool. For finding values in a table, use VLOOKUP or XLOOKUP instead of long nested IFs. For multiple conditions, consider IFS (as above) or SWITCH when you’re matching exact values. For complex criteria, you might combine IF with AND/OR, but if you’re counting or summing based on conditions, use COUNTIF, SUMIF, or AVERAGEIF — they are simpler and faster. For example, =SUMIF(A2:A20,">100") sums only the cells greater than 100, without needing an IF at all.

Frequently Asked Questions

How do I use IF with text? Put the text in double quotes inside the formula, like =IF(A1="Yes","Confirmed","Not confirmed"). Remember that IF is not case-sensitive, so “yes” and “YES” are treated the same.

Can I return a blank cell instead of 0 or FALSE? Yes. Use an empty string for the value_if_false: =IF(A1>0,A1,""). This shows an empty cell when A1 is not greater than zero.

Why does my IF formula show #NAME? This usually means you forgot quotes around text or misspelled the function. Check that the function is written as IF and that any text values are enclosed in double quotes, e.g., "High" not High.

How many IFs can I nest? In Excel 2016 and later, you can nest up to 64 IF functions, but that’s impractical. For more than a few conditions, use IFS or a lookup table.

Does IF work with dates? Yes. Dates are stored as numbers, so you can compare them: =IF(A1>TODAY(),"Future","Past or today") checks if A1 is after today’s date.

What’s the difference between IF and IFS? IF handles one condition and returns two possible values. IFS (Excel 2016+) handles multiple conditions in a single formula, returning the value for the first true condition. Use IFS when you have more than two outcomes.

Related

Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.

More in Formulas & functions

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.