### Syntax

The generic syntax for the IF function looks like this: The first argument, logical_test, is an expression that should return either TRUE or FALSE. The second argument, value_if_true, is the value to return when logical_test is TRUE. The last argument, value_if_false, is the value to return when logical_test is FALSE. Both value_if_true and value_if_false are optional, but at least one of them must be provided. For example, if cell A1 contains 80, then:

### Logical tests

The IF function supports logical operators (>,<,<>,=) when creating logical tests. Most commonly, the logical_test in IF is a complete logical expression that will evaluate to TRUE or FALSE. The table below shows some common examples: Notice text values must be enclosed in double quotes (""), but numbers do not. The IF function does not support wildcards, but you can combine IF with COUNTIF to get basic wildcard functionality. To test for substrings in a cell, you can use the IF function with the SEARCH function.

### Pass or Fail example

In the worksheet shown above, we want to assign either “Pass” or “Fail” based on a test score. A passing score is 70 or higher. The formula in D6, copied down, is: Translation: If the value in C5 is greater than or equal to 70, return “Pass”. Otherwise, return “Fail”. Note that the logical flow of this formula can be reversed. This formula returns the same result: Translation: If the value in C5 is less than 70, return “Fail”. Otherwise, return “Pass”. Both formulas above, when copied down, will return correct results. Note: If you are new to the idea of formula criteria, this article explains many examples.

### Assign points based on color

In the worksheet below, we want to assign points based on the color in column B. If the color is “red”, the result should be 100. If the color is “blue”, the result should be 125. This requires that we use a formula based on two IF functions, one nested inside the other. The formula in C5, copied down, is: Translation: IF the value in B5 is “red”, return 100. Else, if the value in B5 is “blue”, return 125.

There are three things to notice in this example: This is a simple example of a nested IFs formula. See below for a more complex example.

### Return another formula

The IF function can return another formula as a result. For example, the formula below will return A1*5% when A1 is less than 100, and A1*7% when A1 is greater than or equal to 100:

### Nested IF statements

The IF function can be “nested”. A “nested IF” refers to a formula where at least one IF function is nested inside another in order to test for more conditions and return more possible results. Each IF statement needs to be carefully “nested” inside another so that the logic is correct. For example, the following formula can be used to assign a grade rather than a pass / fail result: Up to 64 IF functions can be nested. However, in general, you should consider other functions, like VLOOKUP or XLOOKUP for more complex scenarios, because they can handle more conditions in a more streamlined fashion. For a more details see this article on nested IFs. Note: the newer IFS function is designed to handle multiple conditions without nesting. However, a lookup function like VLOOKUP or XLOOKUP is usually a better approach unless the logic for each condition is custom.

### IF with AND, OR, NOT

The IF function can be combined with the AND function and the OR function. For example, to return “OK” when A1 is between 7 and 10, you can use a formula like this: Translation: if A1 is greater than 7 and less than 10, return “OK”. Otherwise, return nothing (""). To return B1+10 when A1 is “red” or “blue” you can use the OR function like this: Translation: if A1 is red or blue, return B1+10, otherwise return B1. Translation: if A1 is NOT red, return B1+10, otherwise return B1.

### IF cell contains specific text

Because the IF function does not support wildcards, it is not obvious how to configure IF to check for a specific substring in a cell. A common approach is to combine the ISNUMBER function and the SEARCH function to create a logical test like this: For example, to check for the substring “xyz” in cell A1, you can use a formula like this: Read a detailed explanation here.

### More information

Read more about nested IFs Learn how to use VLOOKUP instead of nested IFs (video) 50 Examples of formula criteria

### Notes

The IF function is not case-sensitive. To count values conditionally, use the COUNTIF or the COUNTIFS functions. To sum values conditionally, use the SUMIF or the SUMIFS functions. If any of the arguments to IF are supplied as arrays, the IF function will evaluate every element of the array.

### Dave Bruns

Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.