| | Product Information Help and How-to Training Templates Related Products and Technologies Support and Feedback Technical Resources Additional Resources | Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.
=IF(logical test, value if true, [value if false])
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 Office Excel. DescriptionThe 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. SyntaxIF(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 Required. The value that you want to be returned if the logical_test argument 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 IF function returns the text "Within budget." If logical_test evaluates to TRUE and the value_if_true argument is omitted (that is, there is only a comma following the logical_test argument), the IF function returns 0 (zero). To display the word TRUE, use the logical value TRUE for the value_if_true argument.
- value_if_false Optional. The value that you want to be returned if the logical_test argument 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 IF function returns the text "Over budget." If logical_test evaluates to FALSE and the value_if_false argument is omitted, (that is, there is no comma following the value_if_true argument), the IF function returns the logical value FALSE. If logical_test evaluates to FALSE and the value of the value_if_false argument is omitted (that is, in the IF function, there is no comma following the value_if_true argument), the IF function returns the value 0 (zero).
RemarksExample 1The example may be easier to understand if you copy it to a blank worksheet. How do I copy an example?
- Select the example in this article.
Important Do not select the row or column headers. 
Selecting an example from Help - Press CTRL+C.
- In Excel, create a blank workbook or worksheet.
- In the worksheet, select cell A1, and press CTRL+V.
Important For the example to work properly, you must paste it into cell A1 of the worksheet. - To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
After you copy the example to a blank worksheet, you can adapt it to suit your needs.
|
|
| A | B | C |
|---|
| Data | | | | 50 | 23 | | | Formula | Description | Result | | =IF(A2<=100,"Within budget","Over budget") | If the number in cell A2 is less than or equal to 100, the formula returns "Within budget." Otherwise, the function displays "Over budget." | Within budget | | =IF(A2=100,A2+B2,"") | If the number in cell A2 is equal to 100, A2 + B2 is calculated and returned. Otherwise, empty text ("") is returned. | Empty text ("") |
|
Example 2The example may be easier to understand if you copy it to a blank worksheet. How do I copy an example?
- Select the example in this article.
Important Do not select the row or column headers. 
Selecting an example from Help - Press CTRL+C.
- In Excel, create a blank workbook or worksheet.
- In the worksheet, select cell A1, and press CTRL+V.
Important For the example to work properly, you must paste it into cell A1 of the worksheet. - To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
After you copy the example to a blank worksheet, you can adapt it to suit your needs.
|
|
| A |
B | C |
| Actual Expenses |
Predicted Expenses | |
| 1500 |
900 | |
| 500 |
900 | |
| 500 |
925 | |
| Formula |
Description | Result |
| =IF(A2>B2,"Over Budget","OK") |
Checks whether the expenses in row 2 are over budget | Over Budget |
| =IF(A3>B3,"Over Budget","OK") |
Checks whether the expenses in row 3 are over budget | OK |
|
Example 3The example may be easier to understand if you copy it to a blank worksheet. How do I copy an example?
- Select the example in this article.
Important Do not select the row or column headers. 
Selecting an example from Help - Press CTRL+C.
- In Excel, create a blank workbook or worksheet.
- In the worksheet, select cell A1, and press CTRL+V.
Important For the example to work properly, you must paste it into cell A1 of the worksheet. - To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
After you copy the example to a blank worksheet, you can adapt it to suit your needs.
|
|
| A | B | C |
|---|
| Score | | | | 45 | | | | 90 | | | | 78 | | | | Formula | Description | Result | | =IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F")))) | Assigns a letter grade to the score in cell A2 | F | | =IF(A3>89,"A",IF(A3>79,"B", IF(A3>69,"C",IF(A3>59,"D","F")))) | Assigns a letter grade to the score in cell A3 | A | | =IF(A4>89,"A",IF(A4>79,"B", IF(A4>69,"C",IF(A4>59,"D","F")))) | Assigns a letter grade to the score in cell A4 | C |
|
The preceding example demonstrates how you can nest IF statements. In each formula, the fourth IF statement is also the value_if_false argument to the third IF statement. Similarly, the third IF statement is the value_if_false argument to the second IF statement, and the second IF statement is the value_if_false argument to the first IF statement. For example, if the first logical_test argument (Average>89) evaluates to TRUE, "A" is returned. If the first logical_test argument evaluates to FALSE, the second IF statement is evaluated, and so on. You can also use other functions as arguments. The letter grades are assigned to numbers, using the following key.
| If Score is |
Then return |
| Greater than 89 |
A |
| From 80 to 89 |
B |
| From 70 to 79 |
C |
| From 60 to 69 |
D |
| Less than 60 |
F |
Example 4In this example, the LOOKUP function is used instead of the IF function because there are thirteen conditions to test. You may find the LOOKUP function easier to read and maintain than the IF function. The example may be easier to understand if you copy it to a blank worksheet. How do I copy an example?
- Select the example in this article.
Important Do not select the row or column headers. 
Selecting an example from Help - Press CTRL+C.
- In Excel, create a blank workbook or worksheet.
- In the worksheet, select cell A1, and press CTRL+V.
Important For the example to work properly, you must paste it into cell A1 of the worksheet. - To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
After you copy the example to a blank worksheet, you can adapt it to suit your needs.
|
|
| A | B | C |
|---|
| Score | | | | 45 | | | | 90 | | | | 78 | | | | Formula | Description | Result | | =LOOKUP(A2,{0,60,63,67,70,73,77,80,83,87,90,93,97},{"F","D-","D","D+","C-","C","C+","B-","B","B+","A-","A","A+"}) | Assigns a letter grade to the score in cell A2 | F | | =LOOKUP(A3,{0,60,63,67,70,73,77,80,83,87,90,93,97},{"F","D-","D","D+","C-","C","C+","B-","B","B+","A-","A","A+"}) | Assigns a letter grade to the score in cell A3 | A- | | =LOOKUP(A4,{0,60,63,67,70,73,77,80,83,87,90,93,97},{"F","D-","D","D+","C-","C","C+","B-","B","B+","A-","A","A+"}) | Assigns a letter grade to the score in cell A4 | C+ |
|
Become a fan on Facebook
|