The IF Function can evaluate a TRUE/FALSE condition and return one of two values based on whether a TRUE was evaluated or a FALSE was evaluated.

The IF function is a computer program that you run from a worksheet cell formula. It can evaluate a TRUE/FALSE condition and return one of two values based on whether a TRUE was evaluated or a FALSE was evaluated. You run the IF worksheet function by typing its name in a formula then followed by the information it is suppose to use. The IF function is generally used to make a decision in a worksheet formula thus providing logic for your worksheet. The decision as well as the values the function returns can be a great many things. A common use for the IF function would be to calculate different formulas based upon its TRUE/FALSE decision. For example, if you are calculating a sale and want to give the customer a 10% discount if the sale is above $400.00 then you would use the IF function to accomplish such a task. The IF worksheet function is also heavily used in summarizing data and in protecting against worksheet errors (error protection).

Whenever you type a formula in a worksheet cell, this is called syntax or grammar. The general IF function syntax has a format like this when you type it in a worksheet cell:

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

Where logical_test, [value_if_true], [value_if_false] are called the function argument list. Remember, you are running a computer program at this point so the program needs information to operate and that is why there is an argument list. When you see an argument list and you see square brackets [ ] around the argument name, this means the argument is optional and you do not have to include it when typing unless you need it. So for the syntax above, you need to include one argument for the IF function when typing it in a worksheet cell formula in order for it to calculate correctly. What argument values can be used are discussed below. Remember functions expect certain things in their argument lists, if you do not put the correct information in the list they will generate an error when run.

- logical_test: This can be any value, formula or nested function
that can be evaluated to TRUE / FALSE. For example, B6*B7>=400
is a formula that calculates to TRUE or FALSE . The following relational operators and symbols can be used to build the
logical test formula:
- Less than: <
- Greater than: >
- Less than or equal to: <=
- Greater than or equal to: >=
- Not equal to: <>
- Equal to: =
- Concatenation Operator: &

- Some other important players that are commonly used to build this argument are the IS, AND,OR and NOT functions.

- value_if_true Optional: This is the value that you want to be returned if the logical_test argument evaluates to TRUE. This again can be any value, formula or nested function that generates a value.
- value_if_false Optional: This is the value that you want to be returned if the logical_test argument evaluates to FALSE. This again can be any value, formula or nested function that generates a value.

Since the IF function is a computer program, it runs when you press Enter to enter the formula that contains it. If any of the arguments are wrong, the function will return an error.

When typing the IF function in a worksheet cell formula, you need to replace the argument list with arguments separating each one with a comma (,). Some typical arguments you can use are:

Argument Type | Cell Formula | Explanation |

Cell References and Formulas | =IF( B6*B7 >= 400, B6*B7*.9 , B6*B7 ) | If the logical condition for the IF function evaluates to TRUE then the value from B6*B7*.9 is returned. If FALSE then the value for B6*B7 is returned |

Nested Functions | =IF( ISERROR( A10/A11 ), 0, A10/A11 ) | If the logical condition for the IF function finds an error with the formula A1/A11 then 0 is returned. If ISERROR evaluates to false then the value for A10/A11 is returned (basic formula error protection) |

Cell and Range Names | =IF( Wires, 100, 0 ) | If the cell name wires has a TRUE value, means TRUE is calculated in the cell, then 100 is returned. This strategy is great for adding options. What generates TRUE in the Wires cell can be anything from an ActiveX control output to a formula. |

* It is possible to name a cell or group of cells on a worksheet and use that name in place of a range reference or cell reference. Consult Excel help on how to name a cell.

The worksheet seen below contains some typical worksheet formulas that run the IF worksheet function. Pay close attention to the argument list and the syntax used to write the formula.

A | B | |

1 | Region | A |

2 | Price | $19.99 |

3 | Quantity | 20 |

4 | Use AND , ISNUMBER functions as logical argument to IF function and determine if B7*B8 should be calculated if numbers present in B7, B8 or "" returned. | |

5 | Sub Total | =IF( AND( ISNUMBER(B2), ISNUMBER(B3)) , B2*B3, "") |

6 |

- If creating nested IF functions, up to 64 IF functions can be nested in the value_if_true and value_if_false arguments. Alternatively, you may consider consider using the LOOKUP, VLOOKUP, HLOOKUP, or CHOOSE functions if you are trying to perform a table lookup. Note that if you are nesting even 5 IF functions together to obtain an IF...ELSEIF style structure, we highly recommend you learn how to build a custom VBA worksheet function commonly referred to as a User Defined Worksheet Function or UDF. These functions will outperform any complex formula you can make and are easier to build and manage then the so called mega formulas.
- If using arrays or ranges to build any of the arguments of the IF, every element of the array is evaluated when the IF statement is run.
- Be sure to check out the COUNTIF, COUNTIFS, SUMIF or SUMIFS worksheet functions. These functions also include logic tests and are geared to counting or summing TRUE conditions.

Need Help? Please call us at 1.805.498.7162

Excel Training Services

Microsoft Excel Products

EMAGENIT Company Information

US Military Discounts

Copyright © 2002-2019

EMAGENIT All Rights Reserved