Home / Formulas / IF
Logic Excel + Google Sheets

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

=IF(logical_test, value_if_true, [value_if_false])

The IF function is the foundational building block for spreadsheet decision logic. It returns one value if true, and another if false.

1 logical_test
Required

Any value or expression that evaluates to TRUE or FALSE (e.g. A2 >= 90, B2 = "Pending", or C2 > AVERAGE(C$2:C$10)).

2 value_if_true
Required

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.

3 value_if_false
Optional

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

=IF(A2>=90, "A", IF(A2>=80, "B", IF(A2>=70, "C", "D")))

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)

  1. 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.
  2. 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.
  3. 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:

=IF(AND(A2>=60, B2>=60), "Pass", "Fail")

AND: every condition must be TRUE — both scores need to reach 60.

=IF(OR(A2>=90, B2>=90), "Pass", "Retry")

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:

=IF(ISNUMBER(SEARCH("urgent", A2)), "Priority", "Normal")

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.

Practice: IF Cell Contains Text →
=IF(A2<>"", "Filled", "Empty")

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.

Intro IF statement practice problem

Solve the problem directly in this locked Mini sheet with instant grading, or open it on its dedicated page.

Open full problem →
Description
Hints 0/3
Solutions 1
–
Test case
1
2
3
Reset
Submit
fx
A
B
C
D
E
F
G
1
2
3
4
5
6
7
8
9
10
Loading interactive spreadsheet...
Preparing grid cells and formula calculation engine
○ Ready Enter formula in highlighted cells, then click Submit.

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.