Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Excel functions, or formulas, lie at the heart of the application’s deep well of
capabilities. Today we’ll tackle IF statements, a string of commands that determine
whether a condition is met or not. Just like a yes-no question, if the specified
condition is true, Excel returns one user-determined value and, if false, it returns
another.
The syntax (or sentence structure; that is, the way the commands are organized in
the formula) of an Excel IF statement is: =IF(logic_test, value_if true, value_if_false).
IF statements are used in all programming languages and, although the syntax may
vary slightly, the function provides the same results.
Simple IF statements
1. Past-due notices
In this spreadsheet, the customer’s payment due date is listed in column A, the
payment status is shown in column B, and the customer’s company name is in
column C. The company accountant enters the date that each payment arrives, which
generates this Excel spreadsheet. The bookkeeper enters a formula in column B that
calculates which customers are more than 30 days past due, then sends late notices
accordingly.
A. Enter the formula: =TODAY() in cell A1, which displays as the current date.
In English, this formula means: If the date in cell A4 minus today’s date is greater than
30 days, then enter the words ‘Past Due’ in cell B4, else/otherwise enter the word
‘OK.’ Copy this formula from B4 to B5 through B13.
1
JD Sartain / IDG Worldwide
Use IF statements to flag past-due accounts so you can send notices to those
customers
Once the formulas are entered, you can continue to reuse this spreadsheet forever.
Just change the names at the beginning of each quarter, enter the new grades at the
end of each quarter, and Excel calculates the results.
2
Use an IF statement to convert numeric scores to a pass-fail status.
A. Enter this formula in cell C4: =SUM(B4*10%), then copy from C4 to C5 through C13.
This formula calculates 10 percent of each person’s sales.
B. Enter this formula in cell D4: =IF(B4>10000, C4, “No bonus”), then copy from D4 to D5
through D13. This formula copies the percentage from column C for sales greater
than $10,000 or the words ‘No Bonus’ for sales less than $10,000 into column D.
C. Enter this formula in cell D15: =SUM(D4:D13). This formula sums the total bonus
dollars for the current month.
Nested IF statements
4. Convert scores to grades with nested IF statements
This example uses a “nested” IF statement to convert the numerical Math scores to
letter grades. The syntax for a nested IF statement is this: IF data is true, then do this;
IF data is true, then do this; IF data is true, then do this; IF data is true, then do this;
else/otherwise do that. You can nest up to seven IF functions.
3
The student’s names are listed in column A; numerical scores in Column B; and the
letter grades in column C, which are calculated by a nested IF statement.
Note: Every open, left parenthesis in a formula must have a matching closed, right
parenthesis. If your formula returns an error, count your parentheses.
B. Enter this formula in cell C15: =SUM(C4:C13). This formula sums the total commission
dollars for the current month.
4
JD Sartain / IDG Worldwide
Use a nested IF statement to calculate different commissions based on different
percentages.
5
JD Sartain / IDG Worldwide
Calculate product prices based on quantity.
D. Next, enter the headers Qty Ordered and Qty Cost in cells B11 and C11.
E. Enter the header Wholesale Products in cell A11, then enter as many products as
you like below.
G. And last, enter the following formula in the adjacent cells of column C:
=B12*IF(B12>=101,3.95,IF(B12>=76,5.25,IF(B12>=51,6.3,IF(B12>=26,7.25,
IF(B12>=11,8,IF(B12>=1,8.5,””))))))
Note there are no spaces in this formula. Copy down the formula as far as needed in
column C to apply to all the wholesale products and quantities in columns A and B.
H. Once the order is complete, create a total line: In column A (in this case, A20),
type TOTAL Invoice Amount. In column C (in this case, C20), use the SUM function to
total the column.
Now, that all the formulas are in place, all you have to do each week (or month) is
enter the new quantities in column B, and Excel does the rest. If the prices change,
just modify the matrix at the top of the spreadsheet, and all the other formulas and
totals will automatically adjust.
Multi-function IF statements
7. Using other functions inside the IF statement
6
In this example, we’ll nest two IF statements and insert the SUM function all into the
same formula. The purpose is to determine whether the individual’s goals are less
than, equal to, or greater than the company’s monthly cap.
A. Enter a monthly cap amount in B1, which can be changed every month to reflect
the company’s expectations.
C. Enter the top five marketing persons' goal amounts in cells A4 through A8.
So, what to do if you have a large database that requires a calculation based on
division, and some of the cells contain zeros? Use the following IF statement formula
to address this problem.
A. To track the money collected per month by the staff at Friar Tuck’s Fundraisers,
open a spreadsheet and create the following headers:Dollars in A1, Dollars per
Worker in B1, Dollars Left Over in C1.
7
B. Enter some dollar amounts in column A and the number of staff working per day in
column B. Column B will include some zeroes because, some days, nobody works
(but donations still come in through the mail).
E. Next, move your cursor to B12 and enter this formula =MAX(B2:B11) to locate the
largest number of workers in column B, which is eight.
F. Move your cursor to D12 and enter this formula: =SUM(D2:D11)/B12. The answer is
$392.50 for each of the eight staff members working at Friar Tuck’s Fundraisers.
In this example, we'll use COUNTIF to count the cells in a specific range that are
greater than > a chosen number, less than < a chosen number, equal to a chosen
number, or a combination of two or more logical operators used together.
D. Copy E4 down from E5 to E11, then change the greater than values to a different
number.
C. Then enter the "less than" number in cell H4, so you can verify that the formula
works.
D. Copy G4 down from G5 through G11, then change the less than values to a different
number.
Equal To =
C. Then enter the "equal to" number in cell J4, so you can verify that the formula
works.
D. Copy I4 down from I5 through I11, then change the less than values to a different
number.
NOTE: You can also combine these logical operators to broaden your results. For
example, Greater than or equal to: =COUNTIF($A$4:$A$16,">=1610"); Less than or
equal to: =COUNTIF($A$4:$A$16,"<=1655")
9
JD Sartain / IDG Worldwide
Use COUNTIF to satisfy specific criteria.
In this example, we'll use COUNTIF to count all the cells in a specified range that
match the selected dates, dollars, or text.
E. Enter some dates in column A4:A12; enter some text such as flowers in column
B4:B12, and enter some dollars in column C4:C12.
F. Enter the following formulas in column D "Single Dates," D4, D5, D6, D7, and D8:
G. Enter the following formulas in column E "Single Text String," E4, E5, E6, E7, and
E8:
H. Enter the following formulas in column G "Multiple Text Strings," G4, G5, G6, G7,
and G8:
10
=COUNTIF($B$4:$B$10, "=Lillies")+COUNTIF($B$4:$B$12, "Daisies"); and
=COUNTIF($B$4:$B$10, "=Lillies")+COUNTIF($B$4:$B$12, "Tulips")
I. Enter the following formulas in column I "Dollars," I4, I5, I6, I7, and I8:
=COUNTIF(C4:C12,"<=30"); =COUNTIF($C$4:$C$12,">=100");
=COUNTIF($C$4:$C$12,"<=75"); =COUNTIF($C$4:$C$12,"=50");
=COUNTIF($C$4:$C$12,"<=25")
10. Use SUMIF to add the values in a range that meet your
specific criteria.
Basically, you create a range (or column) of numbers, dates, or text that contains the
data you want your criteria to match. The criteria are the specific value, date, or text
that you want matched from that original range, and the sum range is the column
that will be summed once the criteria is determined.
A. For example, in column A4:A19, enter the five different boroughs in New York:
Manhattan, Brooklyn, Queens, The Bronx, Staten Island.
C. In column C4:C19, enter the dollar amount for the tolls collected on each bridge in
each borough.
D. In column D4:D8, enter the first criteria you want matched; for example,
Manhattan, Queens, the Bronx, etc.
11
E. In column E4:E8, enter the SUMIF formulas: =SUMIF($A$4:$A$19, D4, $C$4:$C$19)
for E4:E8.
F. Use the Function key F4 to make the range (column A) and sum range (column C)
absolute, but not the criteria column D. Then all you have to do is copy the formula
down.
G. In column E9:E13, enter the first criteria you want matched, then enter a second
criteria in F9:F13. Next, enter the SUMIF formula: =SUMIF($A$4:$A$20,D9,$C$4:$C$19)
+ SUMIF($A$4:$A$20,F9,$C$4:$C$19) for E9:E13 and copy down to E13. Notice that the
criteria is matched from Criteria1 (column D) and Criteria2 (column F).
H. In column E14:E19, enter the SUMIF “hardcoded” formula (that just means the
criteria is coded inside the formula: =SUMIF($A$4:$A$19,"Brooklyn",$C$4:$C$19) +
SUMIF($A$4:$A$19,"Queens",$C$4:$C$19) and copy down to E19, then change the
criteria in each formula to match the data in D14:D19.
NOTE: That the criteria can be entered in a separate cell off to the side or hardcoded
into the formula. The benefit of using a separate cell means you can easily change the
criteria without rewriting the formula. Obviously, G (above) is much easier and makes
more sense than hardcoding (H) the criteria inside the formula, but there may be a
situation in the future where the hardcoded solution is a better fit.
12
JD Sartain / IDG Worldwide
Use SUMIF to add values in a range that meet specific criteria.
C. Enter the number of students enrolled in each subject & genre in column C4:C20.
D. Enter the criteria you want matched to get the average number of students in
each subject in D4:D9.
E. Enter the formula in E4:E9; that is: =AVERAGEIF($A$4:$A$20, D4, $C$4:$C$20). Copy
the formula down through E9.
F. Enter the Criteria1 plus the Criteria2 you want matched to get the average number
of students in two specified subjects in D10:D15 and F10:F15.
H. In column E16:E20, enter the AVERAGEIF “hardcoded” formula, which means the
criteria is coded inside the formula: =AVERAGEIF($A$4:$A$20,"History",$C$4:$C$20) +
AVERAGEIF($A$4:$A$20,"Geography",$C$4:$C$20) and then copy down to E20, and
change the criteria in each formula to match the data in D16:D20.
13
JD Sartain / IDG Worldwide
Use AVERAGEIF to average values in a range that meet specific criteria.
B. The question mark (?) represents a single character; for example, m?th could be
math, moth, meth, myth, etc.
C. The tilde (~) identifies a wildcard character (~ * ?) in the text that’s separate from
the keyboard character; that is, the asterisk as a symbol as opposed to a wildcard. For
example, if you wanted to find the exact characters in the word 'moon' followed by
an asterisk (moon*), this search string would return all words with 'moon' at the
beginning, followed by any/all other words with the root word 'moon' such as
moonshine, moonlight, moonstone, etc.). To locate the word 'moon' followed by an
asterisk, use the tilde (~) to tell Excel that the asterisk (in this case) is NOT a wildcard.
The syntax would look like this: moon~*.
14
D. In column A3:A21, enter some related items such as Wally World, Sea World, Fairy
Worlds, etc.
E. In column B3:B11, enter the following formula using the asterisk (*) wildcard:
=COUNTIF($A$3:$A$21,"*world*"), then copy the formula down through B11 changing
the criteria word for each formula such as “*land*”; “*Fairy*”; “*Sea*”; etc.
F. In column C3:C21, enter nine different items of clothing. Because there are 19 rows,
many items will be repeated.
H. In column E3 through E11, enter the following formula using the asterisk (*)
wildcard: =SUMIF($C$3:$C$21,"*Suits*",$D$3:E3). Copy the formula down to E11, then
change the criteria words to Jackets, Jeans, Sweaters, Skirts, Vests, Gloves, Dresses,
and Shoes or choose your own criteria words.
I. In column E12 through E21, enter the following formula using the asterisk (*)
wildcard: =SUMIF($C$3:$C$21,"*Shoes*",$D$3:$D$21) + SUMIF($C$3:$C$21,"*Jeans*",
$D$2:$D$9), then change the criteria words to Shoes & Jeans, Jackets & Vests, Skirts
& Sweaters, Dresses & Shoes, Skirts & Vests, Jeans & Jackets, Suits & Gloves,
Sweaters & Vests, Shoes & Gloves, and Shoes & Suits or choose your own criteria
words.
15
16