Excel IF Function - Microsoft Excel IF Function Tutorial
Microsoft Excel Function Tutorial
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.
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.
|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, "")|