If Function

The IF function runs a logical test and returns one value for a TRUE result, and another for a FALSE result. For example, to “pass” scores above 60: =IF(A1>60,”Pass”,”Fail”). More than one condition can be tested by nesting IF functions. The IF function can be combined with logical functions like AND and OR to extend the logical test.

Syntax

The syntax for the IF function in Microsoft Excel is:

=IF( condition, value_if_true, [value_if_false] )

Parameters or Arguments

condition

The value that you want to test.

value_if_true

It is the value that is returned if condition evaluates to TRUE.

value_if_false

Optional. It is the value that is returned if condition evaluates to FALSE.

Excel If Function Examples

If Function Example 1

The following spreadsheet shows two simple uses of the Excel If function. In these examples, the logical_test checks whether the corresponding value in column A is less than zero and returns:

The text string “negative” if the value in column A is less 0
or
The text string “positive” otherwise (i.e. if the value in column A is greater than or equal to 0).

If Function Example 2

The following spreadsheet shows some more examples of the Excel If function, using different types of logical_test.

If Function Example 3

The following example shows nesting of the Excel If function (i.e. using the if function within another if function). In each case:

  • If the value in column B is equal to 0, a further call to ‘If’ is made, to test the value in column C. Within this If function call:
    • If the value in column C is equal to 0, the function returns the text string “div by zero”;
    • If the value in column C is not equal to zero, the function returns the value in column A divided by the value in column C.
  • If the value in column B is not equal to zero, the function returns the value in column A divided by the value in column B.

IF Function Error

If you get an error from the Excel If Function, this is likely to be the #VALUE! error:

#VALUE!

Occurs if the supplied logical_test argument cannot be evaluated as TRUE or FALSE.