IF AND ITS RELATIVES

advertisement
IF AND ITS RELATIVES
Study the explanations and do the exercises indicated by the arrow head













A conditional statement involves IF; it is a function in Excel and requires a leading =.
The word IF means test (the subsequent condition); thus IF can be an action indicator.
The word IF precedes a condition; the other two arguments are actions, e.g., “WOW” indicates the
action of displaying WOW in the cell after the IF test is finished.
A condition is a phrase based on =, >, < , <> [means NOT EQUAL) such as A1 > A2
The words AND, OR, NOT are operators that can be applied to conditions, e.g.,
o =NOT (A1 > B1)
o =AND( A1 = B2, C1 < D3)
o =OR (A2 <> D6, A5 <> D4)
o Suppose cell A1 contained 7 and B1 contained 6, then putting
=NOT (A1 > B1) in cell F1 would make cell F1 produce the word FALSE. Try it!
A full-fledged IF-function has three parts or arguments:
o What follows the word IF is the condition
o The second part is an action to be performed when the condition is TRUE
o The third part is an action to be performed when the condition is FALSE
o Note: often this third argument is omitted
=IF(A1=3, A2+4, A3+10) means
IF (A1 EQUALS 3, THEN ADD 4 TO A2, ELSE ADD 10 TO A3)
 Now on a worksheet enter 3 in A1, 4 in A2, and 5 in A3; also put the above function in D1,
hit ENTER. What happens?
 Now just change the contents of A1 to 4, hit ENTER; what happens to cell D1?
Note that In a full fledged IF-function, the second action (UNDERLINED BELOW) and third
argument are both actions; since evaluating an IF-function is an action, we can have a formula like
=IF(A1=3, IF(A2 > 3, A3 + 5, A3 - 1), "WOW")
This means IF (A1 = 3
THEN IF (A2 > 3
THEN ADD 5 TO A3
OTHERWISE SUBTRACT 1 FROM A3)
OTHERWISE DISPLAY THE WORD “WOW” IN THE CELL
CONTAINING THE IF FORMULA).
 Now on a worksheet enter 3 in A1, 4 in A2, and 5 in A3, and enter the formula in D2 to see
what happens.
 Now change the contents of A1 to 2, what happens?
The condition above is called a “nested” IF, because one IF formula is nested within another IF
formula.
The arguments of each IF formula must be contained between two parentheses.
There should be an equal number of left and right parentheses in the whole formula.
==========================
SUMIF means add the numbers in a range that meet a certain condition in quotes (such a condition is
always in quotes); thus
=SUMIF(A1:A3, “<5”) means add the first three numbers in column A that are < 5
 Now on a worksheet re-enter 3 in A1, 4 in A2, and 5 in A3, and enter the formula in D3 to
see what happens.
COUNTIF means COUNT all the numbers in a range that meet a certain condition in quotes; thus
=COUNTIF(A1:A3, “<5”) means count the first three numbers in column A that are < 5;
 Enter this function in D4 and see what happens.
Download