# IF function

This article describes the formula syntax and usage of the **IF** function (function: A prewritten formula that takes a value or values, performs an operation, and returns a value or values. Use functions to simplify and shorten formulas on a worksheet, especially those that perform lengthy or complex calculations.) in Microsoft Excel.

## Description

The **IF** function returns one value if a condition you specify evaluates to TRUE, and another value if that condition evaluates to FALSE. For example, the formula **=****IF(****A1>10,"Over 10","10 or less")** returns "Over 10" if A1 is greater than 10, and "10 or less" if A1 is less than or equal to 10.

## Syntax

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

The IF function syntax has the following arguments (argument: A value that provides information to an action, an event, a method, a property, a function, or a procedure.):

**logical_test**Required. Any value or expression that can be evaluated to TRUE or FALSE. For example, A10=100 is a logical expression; if the value in cell A10 is equal to 100, the expression evaluates to TRUE. Otherwise, the expression evaluates to FALSE. This argument can use any comparison calculation operator.**value_if_true**Optional. The value that you want to be returned if theargument evaluates to TRUE. For example, if the value of this argument is the text string "Within budget" and the*logical_test*argument evaluates to TRUE, the*logical_test***IF**function returns the text "Within budget." Ifevaluates to TRUE and the*logical_test*argument is omitted (that is, there is only a comma following the*value_if_true*argument), the*logical_test***IF**function returns 0 (zero). To display the word TRUE, use the logical value TRUE for theargument.*value_if_true***value_if_false**Optional. The value that you want to be returned if theargument evaluates to FALSE. For example, if the value of this argument is the text string "Over budget" and the*logical_test*argument evaluates to FALSE, the*logical_test***IF**function returns the text "Over budget." Ifevaluates to FALSE and the*logical_test*argument is omitted, (that is, there is no comma following the*value_if_false*argument), the*value_if_true***IF**function returns the logical value FALSE. Ifevaluates to FALSE and the value of the*logical_test*argument is blank (that is, there is only a comma following the*value_if_false*argument), the*value_if_true***IF**function returns the value 0 (zero).

## Remarks

- Up to 64
**IF**functions can be nested asand*value_if_true*arguments to construct more elaborate tests. (See Example 3 for a sample of nested*value_if_false***IF**functions.) Alternatively, to test many conditions, consider using the LOOKUP, VLOOKUP, HLOOKUP, or CHOOSE functions. (See Example 4 for a sample of the**LOOKUP**function.) - If any of the arguments to
**IF**are arrays (array: Used to build single formulas that produce multiple results or that operate on a group of arguments that are arranged in rows and columns. An array range shares a common formula; an array constant is a group of constants used as an argument.), every element of the array is evaluated when the**IF**statement is carried out. - Excel provides additional functions that can be used to analyze your data based on a condition. For example, to count the number of occurrences of a string of text or a number within a range of cells, use the COUNTIF or the COUNTIFS worksheet functions. To calculate a sum based on a string of text or a number within a range, use the SUMIF or the SUMIFS worksheet functions.

## Examples

Use the embedded workbook shown here to work with examples of this function. You can inspect and change existing formulas, enter your own formulas, and read further information about how the function works.

### Example 1

These examples use the IF function to test the values in a cell and either return a text string or perform a math operation and then return a value based on the result.

### Example 2

These examples use the IF function to test the values in a cell and return a text string based on the result.

### Example 3

These examples "nest" the IF function inside another IF function to return results based on a cell. If the result of the first IF function is True (>89), the first value specified ("A") is returned. If the result is False, the second IF function text to see if the value is >79 and, if so, returns "B," and additional IF functions test for a "C," "D," and "F" grade.

### Example 4

These examples show an alternative to "nesting" IF functions – the LOOKUP function – to return letter grades based on a cell value.

To work in-depth with this workbook, you can download it to your computer and open it in Excel. For more information, see the article Download an embedded workbook from OneDrive and open it on your computer.