LocalExcelTool
Get started

Excel IF function

IF tests one condition and returns one of two values. It is the base of every business rule in a spreadsheet: hit or miss, taxed or not, in stock or out. The real risk is nesting — past three levels nobody can read it, and that is the point where IFS or a lookup table is the better tool.

Logic · Available in: Excel 97 and every desktop version since

Syntax

IF(logical_test, [value_if_true], [value_if_false])

What it returns The value for the branch that applies — or FALSE if the third argument is left out.

Arguments
logical_testrequiredAnything that evaluates to TRUE or FALSE, such as A2>=90 or B2="Paid".
value_if_trueoptionalWhat to return when the test is TRUE; if omitted, IF returns TRUE.
value_if_falseoptionalWhat to return when the test is FALSE; if omitted, IF returns FALSE.

Examples

Did the rep hit target?

RepSalesTargetHit?
Ana128000120000
Ben96000120000
= IF(B2>=C2,"Yes","No")

→ Yes

128000 >= 120000 is TRUE, so the formula returns Yes. The text branches need quotes — unquoted Yes is read as a defined name and the formula returns #NAME?.

Stop empty rows showing 0

QtyPriceTotal
312.5
= IF(A2="","",A2*B2)

→ 37.5

The first test catches an empty quantity and returns an empty string, so the column does not fill up with zeros. Row 3 stays blank instead of showing 0, which is what makes the sheet printable.

Common mistakes

  • 1.Nesting four or five IFs. Once the brackets pile up the formula cannot be edited; use IFS in Excel 365, or build a lookup table and use XLOOKUP with an approximate match.
  • 2.Leaving text unquoted: IF(A2=Paid,...) is read as a name and returns #NAME?.
  • 3.Text comparison ignores case, so "paid" and "Paid" both count as true. Use EXACT when case matters.
  • 4.Comparing a number with a number stored as text: if A2 holds "120", A2>100 can give a surprising answer. Convert it with VALUE first.

How to use it

  1. 1.Click the cell where the result should appear.
  2. 2.Type = then the function name, and press Tab to accept it.
  3. 3.Enter each argument separated by commas; ranges can be dragged with the mouse.
  4. 4.Press Enter. Drag the fill handle down if the same formula applies to more rows.

Frequently asked questions

What is the syntax of IF?

IF(logical_test, [value_if_true], [value_if_false]). What it returns: The value for the branch that applies — or FALSE if the third argument is left out.

Which Excel versions support IF?

Excel 97 and every desktop version since. It is available in every desktop version unless the note above says otherwise.

Why does IF return an error instead of a value?

Nesting four or five IFs. Once the brackets pile up the formula cannot be edited; use IFS in Excel 365, or build a lookup table and use XLOOKUP with an approximate match.

Related functions

More in this group

Need to get the data in first?

← All Excel formulas