Formulyo

Excel + Google Sheets · Deep guide

IF in Excel: make your sheet decide for you

IF is the function that lets a spreadsheet make a decision: mark an invoice as paid or overdue, label a score as pass or fail, show a warning when a budget is exceeded. Without it you would have to read every row and type the answer by hand.

IF works in every version of Excel and in Google Sheets. In this guide you will see how it is built, a worked example with real numbers and the cases that surprise beginners, such as empty cells and numbers stored as text. See also: SUMIF guide and COUNTIF guide.

How IF works

IF takes three arguments: the test, the value to show if the test is true and the value to show if it is false. Write the formula like this:

=IF(A2>=50,"pass","fail")

Here Excel checks whether the score in A2 is 50 or more. If it is, the cell shows pass, otherwise it shows fail. Texts go in quotes, numbers do not. Works in Excel 2010 or later.

Step by step example

  1. Type a score in A2, for example 70.
  2. Click an empty cell, for example B2.
  3. Type =IF(A2>=50,"pass","fail") and press Enter.
  4. Change the score to 10 and watch the result change to fail.
AB
1Score (A)Result (B)
270pass
310fail
450pass

With 70 the result is pass and with 10 it is fail. An empty cell counts as zero, so it also gives fail. Combine tests with AND or OR when one condition is not enough.

Common errors

  1. The texts are written without quotes and Excel shows a name error. Always put text inside quotes.
  2. A cell contains text instead of a number and the comparison gives a misleading answer. Check it with ISNUMBER first.
  3. An empty cell is treated as zero and shows fail. Add a test for empty cells if that matters.
  4. Too many IF functions nested inside each other become impossible to read. Use IFS or a lookup table instead.

A good habit is to test the formula with three values: one that passes, one that fails and an empty cell. If all three give what you expect, the rule is safe to copy down the whole column.

The same formula in other languages

Get 1 formula a day, free

Plus a free weekly planner template for Excel and Google Sheets. Unsubscribe in 1 click.

✓ Done! Check your inbox to confirm.

Want ready-made templates? See the Formulyo pack →

Keep learning