LikeOffice.com

excel utility

Keep In Touch:
 contact us  facebook
 
Get HELP with your Excel Project:
 Excel Formula
 List of Excel Formula examples
 
Home >> excel 2007 >> Excel 2007 - Logical functions

This page presents how to work with Microsoft Excel 2007 features and its redesigned interface. You may also visit our Excel Question page.

 

   Logical functions

   AND function

   FALSE function

   IF function

   IFERROR function

   NOT function

   OR function

   TRUE function

 


Logical functions

Click one of the links in the following list to see detailed help about the function.

Function

Description

AND

Returns TRUE if all of its arguments are TRUE

FALSE

Returns the logical value FALSE

IF

Specifies a logical test to perform

IFERROR

Returns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula

NOT

Reverses the logic of its argument

OR

Returns TRUE if any argument is TRUE

TRUE

Returns the logical value TRUE

 

See Also

 

 

Excel > Function reference > Logical

AND function

Excel 2007

This article describes the formula syntax and usage of the AND 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.

Description

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.

Syntax

AND(logical1, [logical2], ...)

The AND 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.):

  • logical1  Required. The first condition that you want to test that can evaluate to either TRUE or FALSE.
  • logical2, ...  Optional. Additional conditions that you want to test that can evaluate to either TRUE or FALSE, up to a maximum of 255 conditions.

Remarks

Example 1

The example may be easier to understand if you copy it to a blank worksheet.

How do I copy an example?

  1. Select the example in this article.

Important  Do not select the row or column headers.

Selecting an example from Help

  1. Press CTRL+C.
  2. In Excel, create a blank workbook or worksheet.
  3. 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.

  1. 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.

How do I copy an example?

  1. Select the example in this article.

Important  Do not select the row or column headers.

Selecting an example from Help

  1. Press CTRL+C.
  2. In Excel, create a blank workbook or worksheet.
  3. 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.

  1. 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

Displays TRUE if the number in cell A2 is between 1 and 100. Otherwise, it displays FALSE.

TRUE

=IF(AND(1

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

Displays the number in cell A2, if it is between 1 and 100. Otherwise, it displays a message.

50

 

See Also

 

 

Excel > Function reference > Logical

FALSE function

Returns the logical value FALSE.

Syntax

FALSE( )

Remark

You can also type the word FALSE directly onto the worksheet or into the formula, and Microsoft Excel interprets it as the logical value FALSE.

 

See Also

 

 

Excel > Function reference > Logical

IF function

Excel 2007

Tags  conditional; formula; functions; IF function; lookup; test; VALUE; vlookup

What are tags?

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.

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  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

Example 1

The example may be easier to understand if you copy it to a blank worksheet.

How do I copy an example?

  1. Select the example in this article.

Important  Do not select the row or column headers.

Selecting an example from Help

  1. Press CTRL+C.
  2. In Excel, create a blank workbook or worksheet.
  3. 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.

  1. 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.

How do I copy an example?

  1. Select the example in this article.

Important  Do not select the row or column headers.

Selecting an example from Help

  1. Press CTRL+C.
  2. In Excel, create a blank workbook or worksheet.
  3. 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.

  1. 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.

How do I copy an example?

  1. Select the example in this article.

Important  Do not select the row or column headers.

Selecting an example from Help

  1. Press CTRL+C.
  2. In Excel, create a blank workbook or worksheet.
  3. 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.

  1. 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

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 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.

How do I copy an example?

  1. Select the example in this article.

Important  Do not select the row or column headers.

Selecting an example from Help

  1. Press CTRL+C.
  2. In Excel, create a blank workbook or worksheet.
  3. 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.

  1. 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

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+

Related Office Online discussions

Read related questions and answers from other Microsoft Office customers.

 

See Also

 

 

Excel > Function reference > Logical

IFERROR function

Excel 2007

Returns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula. Use the IFERROR function to trap and handle errors in a formula (formula: A sequence of values, cell references, names, functions, or operators in a cell that together produce a new value. A formula always begins with an equal sign (=).).

Syntax

IFERROR(value,value_if_error)

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.

How to copy an example

  1. Create a blank workbook or worksheet.
  2. Select the example in the Help topic.

 Note    Do not select the row or column headers.

Selecting an example from Help

  1. Press CTRL+C.
  2. In the worksheet, select cell A1, and press CTRL+V.
  3. 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.

How to copy an example

  1. Create a blank workbook or worksheet.
  2. Select the example in the Help topic.

 Note    Do not select the row or column headers.

Selecting an example from Help

  1. Press CTRL+C.
  2. In the worksheet, select cell A1, and press CTRL+V.
  3. 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.

 

See Also

 

 

Excel > Function reference > Logical

NOT function

Excel 2007

Reverses the value of its argument. Use NOT when you want to make sure a value is not equal to one particular value.

Syntax

NOT(logical)

Logical   is a value or expression that can be evaluated to TRUE or FALSE.

Remark

If logical is FALSE, NOT returns TRUE; if logical is TRUE, NOT returns FALSE.

Example

The example may be easier to understand if you copy it to a blank worksheet.

How to copy an example

  1. Create a blank workbook or worksheet.
  2. Select the example in the Help topic.

 Note    Do not select the row or column headers.

Selecting an example from Help

  1. Press CTRL+C.
  2. In the worksheet, select cell A1, and press CTRL+V.
  3. 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)

 

See Also

 

 

Excel > Function reference > Logical

OR function

Excel 2007

Returns TRUE if any argument is TRUE; returns FALSE if all arguments are FALSE.

Syntax

OR(logical1,logical2,...)

Logical1,logical2,...   are 1 to 255 conditions you want to test that can be either TRUE or FALSE.

Remarks

Example

The example may be easier to understand if you copy it to a blank worksheet.

How to copy an example

  1. Create a blank workbook or worksheet.
  2. Select the example in the Help topic.

 Note    Do not select the row or column headers.

Selecting an example from Help

  1. Press CTRL+C.
  2. In the worksheet, select cell A1, and press CTRL+V.
  3. 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

Formula

Description (Result)

=OR(TRUE)

One argument is TRUE (TRUE)

=OR(1+1=1,2+2=5)

All arguments evaluate to FALSE (FALSE)

=OR(TRUE,FALSE,TRUE)

At least one argument is TRUE (TRUE)

 

See Also

 

 

Excel > Function reference > Logical

TRUE function

Returns the logical value TRUE.

Syntax

TRUE( )

Remark

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.

 

                  

Microsoft® and Microsoft Excel® are registered trademarks of Microsoft Corporation.
©2003-2013 LikeOffice - Privacy Policy - Contact us