IF: make Excel decide

Show Pass or Fail, Paid or Owing, Reorder or OK — automatically, from a rule you write once.

Module 4: Decisions and lookups · Lesson 17 of 45 · 14 min read · Free

Every office has rules: if the score is 40 or more, the student passes; if stock is at or below 30, reorder; if the customer paid in full, mark it Paid. The IF function turns a rule like that into a formula.

The three parts of an IF formula

=IF(test, value_if_true, value_if_false)

Open m4-decisions-lookups-practice.xlsx, sheet Results. The pass mark (40) is in H1. In C2:

=IF(B2>=$H$1, "Pass", "Fail")

Copy it down. Every student now shows Pass or Fail, and if the school changes the pass mark to 45, you change H1 and the whole column updates. (Notice $H$1 — the absolute reference from Module 3.)

The comparison operators

The test is a comparison that is either TRUE or FALSE:

OperatorMeansExample test
=equal toH2="Transfer"
<>not equal toD2<>"Yes"
>greater thanG2>50000
<less thanE2<30
>=at leastB2>=40
<=at mostE2<=F2

IF can return numbers and formulas too

IF isn't only for labels. It can calculate:

  • Commission: =IF(B2>=3000000, B2*5%, B2*2.5%) — 5% for sales of ₦3m or more, otherwise 2.5%.
  • Delivery fee: =IF(F2>=20000, 0, 1500) — free delivery on orders of ₦20,000 or more.
  • Leave blank: =IF(E2="", "", E2*F2) — calculate only when there's a quantity; "" shows an empty cell.

Check yourself

Answer in your head first, then open each question to see the answer and why.

  1. Which formula shows "Reorder" when stock in E2 is 30 or less, otherwise "OK"?

    • A =IF(E2<30,"Reorder","OK")
    • B =IF(E2<=30,"Reorder","OK")
    • C =IF(E2>=30,"Reorder","OK")
    • D =IF(E2<=30,Reorder,OK)
    Show the answer

    B) =IF(E2<=30,"Reorder","OK") — <= means "at most". Text results need quotes.

  2. What does =IF(F2>=20000,0,1500) return when F2 is 15000?

    • A 0
    • B 1500
    • C 20000
    • D TRUE
    Show the answer

    B) 1500 — 15000 is not >= 20000, so the test is FALSE and IF returns 1500.

  3. Which operator means "not equal to" in Excel?

    • A !=
    • B <>
    • C ><
    • D =/=
    Show the answer

    B) <> — Excel uses <> for not equal.

More free lessons: Why Excel, and how this course works · A tour of the Excel window · Number formats: naira, percentages, dates and phone numbers · Your first formulas: + − × ÷ and the order Excel follows · Cleaning messy text: TRIM, PROPER and Flash Fill · Excel Tables: the habit that saves hours · Choosing the right chart · Your first PivotTable · Printing that looks right the first time · Revision guide and how the final exam works