Returns TRUE if all its arguments evaluate to TRUE; returns FALSE if one or more arguments evaluate to FALSE.
One common use for the AND function is to expand the usefulness of other functions that perform logical tests. For example, the IF function performs a logical test and then returns one value if the test evaluates to TRUE and another value if the test evaluates to FALSE. By using the AND function as the logical_test argument of the IF function, you can test many different conditions instead of just one.
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.
1
2
3
4
A
B
C
Formula
Description
Result
=AND(TRUE, TRUE)
All arguments are TRUE
TRUE
=AND(TRUE, FALSE)
One argument is FALSE
FALSE
=AND(2+2=4, 2+3=5)
All arguments evaluate to TRUE
TRUE
Example 2
The example may be easier to understand if you copy it to a blank worksheet.
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.
1
2
3
4
5
6
7
A
B
C
Data
50
104
Formula
Description
Result
=AND(1<A2, A2<100)
Displays TRUE if the number in cell A2 is between 1 and 100. Otherwise, it displays FALSE.
TRUE
=IF(AND(1<A3, A3<100), A3, "The value is out of range.")
Displays the number in cell A3, if it is between 1 and 100. Otherwise, it displays the message "The value is out of range."
The value is out of range.
=IF(AND(1<A2, A2<100), A2, "The value is out of range.")
Displays the number in cell A2, if it is between 1 and 100. Otherwise, it displays a message.
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.
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).
Remarks
Up to 64 IF functions can be nested as value_if_true and value_if_false arguments to construct more elaborate tests. (See Example 3 for a sample of nested 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.)
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.
Example 1
The example may be easier to understand if you copy it to a blank worksheet.
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.
1
2
3
4
5
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 2
The example may be easier to understand if you copy it to a blank worksheet.
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.
1
2
3
4
5
6
7
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 3
The example may be easier to understand if you copy it to a blank worksheet.
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.
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 4
In 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.
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.
Value is the argument that is checked for an error.
Value_if_error is the value to return if the formula evaluates to an error. The following error types are evaluated: #N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL!.
Remarks
If value or value_if_error is an empty cell, IFERROR treats it as an empty string value ("").
If value is an array formula, IFERROR returns an array of results for each cell in the range specified in value. See the second example below.
Example: Trapping division errors by using a regular formula
The example may be easier to understand if you copy it to a blank worksheet.
In the worksheet, select cell A1, and press CTRL+V.
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.
1
2
3
4
5
6
7
8
9
10
A
B
Quota
Units Sold
210
35
55
0
23
Formula
Description (result)
=IFERROR(A2/B2, "Error in calculation")
Checks for an error in the formula in the first argument (divide 210 by 35), finds no error, and then returns the results of the formula (6)
=IFERROR(A3/B3, "Error in calculation")
Checks for an error in the formula in the first argument (divide 55 by 0), finds a division by 0 error, and then returns value_if_error (Error in calculation)
=IFERROR(A4/B4, "Error in calculation")
Checks for an error in the formula in the first argument (divide "" by 23), finds no error, and then returns the results of the formula (0).
Example: Trapping division errors by using an array formula
The example may be easier to understand if you copy it to a blank worksheet.
In the worksheet, select cell A1, and press CTRL+V.
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.
1
2
3
4
5
6
7
8
9
A
B
C
Quota
Units Sold
Ratio
210
35
=IFERROR(A2:A4/B2:B4, "Error in calculation")
55
0
23
Formula
Description (result)
=C2
Checks for an error in the formula in the first argument in the first element of the array (A2/B2 or divide 210 by 35), finds no error, and then returns the result of the formula (6)
=C3
Checks for an error in the formula in the first argument in the second element of the array (A3/B3 or divide 55 by 0), finds a division by 0 error, and then returns value_if_error (Error in calculation)
=C4
Checks for an error in the formula in the first argument in the third element of the array (A4/B4 or divide "" by 23), finds no error, and then returns the result of the formula (0)
Note The formula in the example must be entered as an array formula. After copying the example to a blank worksheet, select the range C2:C4, press F2, and then press CTRL+SHIFT+ENTER.
In the worksheet, select cell A1, and press CTRL+V.
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.
1
2
3
A
B
Formula
Description (Result)
=NOT(FALSE)
Reverses FALSE (TRUE)
=NOT(1+1=2)
Reverses an equation that evaluates to TRUE (FALSE)
In the worksheet, select cell A1, and press CTRL+V.
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.
You can enter the value TRUE directly into cells and formulas without using this function. The TRUE function is provided primarily for compatibility with other spreadsheet programs.