Excel IF function
The IF statement returns one value when a condition is true (if then) and another when false (if else). Chain nested IFs or IFS for multiple thresholds, and combine with AND / OR for multi-condition tests.
IF statement syntax & arguments
The IF function is the foundational building block for spreadsheet decision logic. It returns one value if true, and another if false.
Any value or expression that evaluates to TRUE or FALSE (e.g. A2 >= 90, B2 = "Pending", or C2 > AVERAGE(C$2:C$10)).
The value to return when logical_test is TRUE. Can be double-quoted text (e.g. "Pass"), a number, a cell reference, or another calculation.
The value to return when logical_test is FALSE. If omitted, returns FALSE. Often chained with another nested IF for tiered grading.
Interview classic: letter-grade ladder
Evaluate thresholds strictly top-down (90 first, then 80, then 70). Once a condition matches, subsequent conditions are skipped.
How to write an IF statement in Excel (IF then / IF else)
- Start with the condition (logical_test) — Decide what to test: A2>=90 for a grade line, B2="Done" for a status match. The test must evaluate to TRUE or FALSE.
- Add the two outcomes — value_if_true is the if-then result; value_if_false is the if-else result. Wrap text values in double quotes.
- Chain IFs or switch to IFS — One IF handles two outcomes. For more thresholds, nest the next IF inside value_if_false — or use the IFS function in modern Excel.
IF with AND / OR: multiple conditions in one IF
The IF condition holds a single logical test. Nest AND or OR inside it to check several cells or thresholds at once:
AND: every condition must be TRUE — both scores need to reach 60.
OR: any single TRUE is enough — one score of 90 or higher passes.
IF cell contains text & IF not blank
IF has no built-in "contains" test. The classic pattern searches for the text, then converts the result to TRUE/FALSE with ISNUMBER:
SEARCH locates "urgent" inside A2 (case-insensitive) and returns a position number — or an error when missing; ISNUMBER turns that into TRUE/FALSE for IF. Use FIND for a case-sensitive match.
IF not blank: <>"" means "not equal to empty". To test for blank cells directly, use ISBLANK(A2).
Nested IF vs Modern IFS
Nested IF
Universal compatibility across all Excel versions, Sheets, and interview assessments. Easy to understand when read top-to-bottom.
IFS
Cleaner for many branches in modern Excel & Sheets: =IFS(A2>=90,"A", A2>=80,"B", A2>=70,"C", TRUE,"D"), avoiding closing parenthesis piles.
Common mistakes & gotchas
- Order matters — Threshold order matters: If you test A2>=70 first, a score of 95 will immediately match C. Always check highest thresholds first.
- Text quotes — Text return values must have quotes: "A", not bare A. Without quotes, Excel assumes it is a named range and triggers #NAME? error.
- Blank cells — Blank cells vs zero: Excel may treat blank cells as zero in certain mathematical comparisons. Use ISBLANK if empty cells need separate handling.
Related practice problems
Practice combining IF statements, lookups, and math formulas in realistic, bite-sized challenges.
FAQ
What is the IF formula syntax?
Use =IF(logical_test, value_if_true, value_if_false). For example =IF(A2>=60, "Pass", "Fail") returns Pass when A2 is at least 60, otherwise Fail.
How do I write an IF statement in Excel?
Start with the condition, then the two outcomes: =IF(A2>=90, "A", "B"). For more than two results, nest the next IF inside value_if_false, or use the IFS function in modern Excel and Google Sheets.
How do I use IF with AND and OR?
Nest them in the condition: =IF(AND(A2>=60, B2>=60), "Pass", "Fail") requires both tests to pass; replace AND with OR to pass when any single test is TRUE.
How do I check if a cell contains specific text with IF?
Combine ISNUMBER with SEARCH: =IF(ISNUMBER(SEARCH("urgent", A2)), "Priority", "Normal"). SEARCH is case-insensitive; use FIND for a case-sensitive match.
How do I write IF not blank in Excel?
Compare against an empty string: =IF(A2<>"", "Filled", "Empty"). To test for blank cells directly, use =IF(ISBLANK(A2), "Blank", "Has value").
What's the difference between IF, COUNTIF, and SUMIF?
IF returns one of two values based on a condition; COUNTIF counts cells matching a condition; SUMIF sums values matching a condition. They often work together: COUNTIF/SUMIF for aggregation, IF for per-row decisions.
When should I use nested IF vs IFS?
Nested IF works everywhere. IFS is cleaner for many branches in modern Excel and Google Sheets.
Why does my nested IF return the wrong grade?
Order matters. Put the highest threshold first so earlier true conditions win.