Professional Documents
Culture Documents
Excel XP Level 4 Vicon
Excel XP Level 4 Vicon
Excel XP Level 4 Vicon
Level 4
ABOUT VICON
Vicon Learning Systems (VLS), the parent company of JaxWorks.com, provides computer
training products and services with a focus on helping its customers improve productivity through
the successful implementation of technology.
The training materials are for the students' use both during the self-administered course and as a
reference guide.
For more information and a list of other available products, please visit us at our web site at
www.jaxworks.com.
Trademarked names appear throughout this book. Rather than list the names and entities that own
the trademarks or insert a trademark symbol with each mention of the trademark name, Vicon
Learning Systems states that it is using the names for editorial purposes and to the benefit of the
trademark owner with no intention of infringing upon the trademark.
DISCLAIMER
Vicon Learning Systems made every effort to ensure the accuracy of this manual. If you should
discover any discrepancies, please notify us immediately at:
www.jaxworks.com/feedback.htm
DISCLAIMER ............................................................................................................ I
INDEX......................................................................................................................165
• Format dates
• Revise formulas
Lesson 1 - Using Other Functions Excel XP Level 4
δ Discussion
Excel functions serve as shortcuts for worksheet computations. A function is a
prewritten formula that takes one or more values, performs an operation on them, and
returns a value. Functions simplify and shorten formula creation by performing
lengthy or complex calculations with a single command.
The values that a function uses to perform a calculation are called arguments.
Arguments can consist of cell addresses, values, text, cell names, or a combination
thereof. Other functions can also be used as arguments; this is known as nesting
functions.
Functions require a set of parentheses around the function itself. More complex
functions may also require additional sets of parentheses around the arguments within
it. No matter how many sets of parentheses are included in a function, they must
always appear in pairs; if you include an opening parenthesis without a matching
closing parenthesis or vice versa, Excel cannot calculate the function and will display
an error message.
The syntax of a function is its required structure; if the syntax of a function is not
correct, Excel cannot perform the calculation. The basic function syntax requires an
equal sign (=), the function name, the opening parenthesis, the required arguments,
and the closing parenthesis.
The Insert Function dialog box provides an easy and accurate method of creating a
function containing several arguments. This dialog box allows you to browse
functions and view an explanation of each one. When you select a function, the
Function Argument dialog box opens and guides you in creating the function
arguments in their proper order.
δ Discussion
Excel organizes its functions into categories. The Financial category includes a large
number of functions that can be used to create calculations such as the payment on a
loan, the interest rate on an investment or loan, the interest payment on an investment
over time, and the future value of an annuity or investment.
Financial function arguments must be entered in the proper order. Most financial
functions include required arguments and additional optional arguments. The
definitions of some common financial functions and the syntax of their required
arguments are listed in the following table:
Function Syntax
PMT (Payment) calculates the payment on a =PMT(rate,nper,pv)
loan, such as a mortgage, based on a constant
interest rate payment.
FV (Future Value) calculates the value an =FV(rate,nper,pmt)
annuity will be worth given a series of
payments invested at an interest rate over a
specified period.
PV (Present Value) calculates the current value =PV(rate,nper,pmt)
of a series of payments.
RATE calculates the interest rate of periodic =RATE(nper,pmt,pv)
payments to an annuity or loan.
Some of the common arguments required by financial functions are defined in the
following table:
Arguments Definition
rate The amount of interest charged yearly for a loan or
investment. The interest can be entered as a decimal or
percentage. For example, 10% can be entered as 0.1 or
10%.
nper The number of payments it will take to repay the loan or
investment.
pv The value an annuity is worth at the present time if a
series of future payments are made. In the case of a loan,
this would be the full amount of the loan. You should be
careful not to include a comma in the amount.
Arguments Definition
fv The value that an annuity will be worth in the future
after the last payment has been made. You should be
careful not to include a comma in the amount.
pmt A fixed payment made each period.
The entries for rate and nper should be in consistent units. When calculating the
payment on a loan of $170,000 at 10% annual interest over 30 years, the result of the
function =PMT(10%,30,170000) is payments of approximately $18,000 per year. To
calculate the monthly payments, divide the interest rate by 12 and multiply the
number of payment periods by 12. The result of the function
=PMT(10%/12,30*12,170000) is payments of approximately $1,500 per month.
φ Step-by-Step
From the Student Data directory, open ADVFNCT.XLS.
Use a financial function.
Use the PMT function to calculate the annual payment for a loan.
Type the following cell references into the corresponding argument boxes:
Enter B15 into the Nper box and B13 into the Pv box.
The results should be a payment of negative $72,252 per year. (The parentheses
around the payment indicate a negative value. The result is negative because it is
money to be paid (a loss) rather than money to be received (profit).)
Practice the Concept: Scroll down to view rows 25 to 38. Select cell D37. Use the
FV function to calculate the future value of the investment. Your results should be
(positive) $543,042.
δ Discussion
Logical functions make decisions based on criteria. If the criteria evaluates to false,
one action is taken; if the criteria evaluates to true, a different action is taken. This
decision-making capability makes logical functions one of the most powerful groups
of functions in Excel.
The IF function returns one value if a condition is true and another value if a
condition is false. For example, you can compare the values of goods shipped to a
customer. If a shipped value is greater than a set figure, the customer receives a
discount. If a shipped value is less than a set figure, the customer does not receive a
discount.
You can also use the IF function to display text as a result of a logical test, but you
must enclose the text in the formula in quotation marks.
Component Description
logical test This component is the test condition. It can contain
cell references, text in quotes, cell names, and
numbers. You can use one or more of the following
comparison operators:
= equal to
<> not equal to
> greater than
>= greater than or equal to
< less than
<= less than or equal to
value if true The result produced if the logical test is true. It can
be a number, formula, cell reference, cell name, text
in quotes, or another function.
value if false The result produced if the logical test is false. It can
be a number, formula, cell reference, cell name, text
in quotes, or another function.
IF Function Result
=IF(B7>10,C7*.1,0) The function tests if the number in
cell B7 is greater than 10. If this is
true, the number in cell C7 is
multiplied by 0.1 and the result is
entered into the current cell. If it is not
true, a zero is entered into the current
cell.
=IF(B7<>10,"GOOD","NO The function tests if the number in
GOOD") cell B7 is not equal to 10. If this is
true, the text GOOD is entered into
the current cell. If the number in cell
B7 is equal to 10, the text NO GOOD
is entered into the current cell.
Creating an IF function
φ Step-by-Step
Use a logical function.
Customers receive a 10% discount on all orders above $400. Use the IF function to
determine if the order is greater than $400. If the order is greater than $400, calculate
10% of the order; if it is not, there is no discount.
Since the order is over $400, the customer receives a discount of $41.95.
Practice the Concept: Select cell F18 and create an IF function that displays the
message You have earned a 10% discount if the order is over $400. Otherwise, no
message is displayed. Use the following IF function to create the message:
=IF(F13>400,"You have earned a 10% discount","").
In the QTY column, select cell C9 and change the quantity to 5. The order now falls
below $400. Notice that the customer does not receive a discount and no message
appears below the order form. Change the quantity in cell C10 to 20 and view the
changes.
δ Discussion
When you enter a date into a cell, Excel formats the date and stores it as the serial
number that represents that date on the calendar. Excel treats dates as numbers so that
it can perform calculations on them, such as determining how many days a bill is past
due.
You can either type a specific date into a worksheet or use a date function to enter a
date. For example, you can enter the same date by typing 2/20/99 or by entering the
function =DATE(1999,2,20). The date function is often used when the year, day, and
month information already exist in separate cells in the worksheet.
Excel also provides a date function that inserts the current date as a field that
automatically updates each time you open the workbook. Some formulas require an
updated current date to increment. For example, to calculate a person’s age, you need
two dates: the birth date and the current date. The birth date is an absolute date, since
that date cannot change. The current date, however, would have to change each day
for the formula to calculate the result correctly.
Similarly, to calculate how many days a bill is past due, you also need two dates: the
date when the bill was due and the current date. The date when the bill was due is an
absolute date, since that date does not change. The current date, however, would have
to change each day for the formula to calculate the result correctly .
The most commonly used date functions are described in the following table:
Function Description
=DATE(year,month,day) The DATE function is used to enter a
specific date into a cell. You enter the
number of the month, day, and year as the
arguments. You can also reference cell
addresses, if one or more arguments are
stored in a cell.
=TODAY() The TODAY function displays the current
date in a date format. This function does
not use arguments. The serial number for
this function is a whole number.
=NOW() The NOW function displays the current
date and time in a date format. This
function does not use arguments. The
serial number for this function displays
the time of day as a decimal.
ο If you type a year between 1900 and 1929 as two digits, Excel
assumes that the date is in the 21st century. Therefore, typing
2/13/25 returns the serial number for the date 2/13/2025. You
must type all four digits to designate any years between 1900
and 1929.
ο You can also calculate time of day values. Time of day values
can be formatted using the Time category on the Number
page in the Format Cells dialog box.
φ Step-by-Step
Use a date function.
Enter 6 in the Month argument box and 20 in the Day argument box.
Practice the Concept: Type the =NOW() function into cell C3 to insert the current
date and time as a field that automatically updates whenever the workbook
recalculates. There are no arguments for this function.
Select cell F6 and create a formula that calculates the length of employment, in years,
for the first employee. The formula should read =($C$3-E6)/365. (Cell C3 must be
entered as an absolute reference, since all hire dates must be subtracted from the
current date to achieve the desired result. Since the answer provides the length of
employment in days, the result is divided by 365 to calculate the number of years.)
Decrease the number of decimals to 1 and then copy the formula down to cell F17.
FORMATTING DATES
δ Discussion
The default formatting used by Excel for dates, times, currency, and numbers is a
Windows function controlled by the Regional Options dialog box in Windows 2000,
or the Regional Settings Properties dialog box in Windows 95/98.
If the default short date format for your system is M/d/yy, then Excel uses this format
for dates and only displays the last two digits of the year. Therefore, even if you type
3/11/2001 into a cell or use the DATE function =DATE(2001,3,11), the cell displays
3/11/01. If you want to display all four digits of the year in a date, you can either
change the default system format or format the worksheet cell containing the date.
In addition to the short date format, there are many other preset formats available on
the Number page of the Format Cells dialog box.
Formatting a date
φ Step-by-Step
Format dates.
REVISING FORMULAS
δ Discussion
You can revise a formula or function in the same manner you would edit any cell. You
can modify the cell addresses, arguments, operators, or even the name of the function
used. Formulas are often revised to create an absolute reference for one or more cell
addresses. Revising a formula is usually more efficient than creating the formula
again.
You can revise a formula in the formula bar or in the cell itself, using standard word
processing methods. When you edit a function, a tooltip appears. You can use the
tooltip to quickly select the text of the argument you want to edit.
Revising a formula
ο You can also use the Insert Function button on the formula
bar to edit a function.
φ Step-by-Step
Revise a formula.
Close ADVFNCT.XLS.
EXERCISE
USING OTHER FUNCTIONS
ε Task
Use financial, logical, and date functions.
1. Open Advfnex.
2. Display the Financial worksheet, if necessary. Create an NPER
function in cell D16 to calculate the number of years it will take for
the annuity to be worth $500,000. (Hint: Use the Insert Function
button to help you with the order of the arguments.)
3. Scroll down to view rows 24 to 39.
4. Use the PMT function in cell D39 to determine the monthly
mortgage payments. (Hint: You need to divide the interest rate by 12
and multiple the number of years, nper, by 12.)
5. Display the Logical worksheet. Create an IF function in cell H6 to
calculate a bonus if the Qtr2 sales is greater than the Qtr1 sales.
Salespeople receive a bonus of 8% of their Qtr2 sales if they exceed
the Qtr1 sales; otherwise, they do not receive a bonus.
6. Copy the formula down to the range H7:H12.
7. Display the Date worksheet. Use the DATE function to enter the
date June 20, 2001 in cell B4.
8. Use the NOW function to enter the current date in cell B6.
9. Select cell B10 and use the DATE function to enter yesterday’s date.
10. Copy cell B10 to cell B11. Change the month argument in cell B11
to the previous month.
11. Change the format for the range B4:B12 to the 14-Mar-2001 format.
12. Select cell C10 and calculate the number of days worked on the
booth by subtracting the starting date from the current date. (Hint:
Make the current date in cell B6 an absolute reference so that you
can copy it.)
13. Format the answer in cell C10 with a number format and one
decimal place. Then, copy the formula to C11.
14. Close the workbook without saving it.
• Assign names
δ Discussion
You can assign a name to a cell or a range in a worksheet. Once a name has been
assigned, the name can be used in any instance where you can use a cell address. For
example, you can use names for ranges in dialog boxes and formulas.
You can use names to refer to cells, ranges, multiple ranges, and ranges in other
worksheets.
δ Discussion
You can use a name to move quickly to a cell or a range. Since a name assigned in a
worksheet is available in all worksheets in the workbook, you can use names to move
easily between the worksheets. For example, in a workbook containing worksheets for
different products, you can quickly jump to the desired product worksheet using the
name assigned to it.
You use the Name Box list to jump to a named range. The Name Box list is located at
the left end of the formula bar and displays all the assigned names in a workbook.
When you choose a name from the Name Box list, the range is selected and the active
cell appears in the first cell of the range.
ο If the formula bar is not displayed, you can use the View menu
to view it.
φ Step-by-Step
From the Student Data directory, open NAME1.XLS.
Jump to a named range.
Notice that the active cell moved to the Qtr 4 worksheet. Use the Qtr1_NetProfits
name on the Name Box list to return to the Qtr 1 worksheet.
ASSIGNING NAMES
δ Discussion
You can use names instead of cell references in formulas and dialog boxes. For
example, if you are summing totals from several worksheets, you can assign names to
the totals in each worksheet and then use the range names in the formula instead of the
cell addresses.
You can use the Name Box to assign range names. The following rules apply to
naming ranges:
φ Step-by-Step
Assign a name to a range.
δ Discussion
You can use a name rather than a cell address in a formula. Using a name in a formula
makes the formula easier to read and understand. For example, it is easy to understand
what information the following formula calculates; =INCOME-EXPENSES. If the
named cells change, the formula automatically updates.
Since names are absolute, you can use a name in place of an absolute cell reference in
a formula. For example, if you are calculating a percentage of a range named Total,
the formula will always refer to the Total range if you use the name rather than the
cell address, no matter where you move or copy the formula.
ο You can also select a name from the Paste Name dialog box to
insert a name into a formula. To use the Paste Name dialog
box, begin the formula. When you need to reference the name
in the formula, press the [F3] key and double-click the desired
name.
ο You can also access the Paste Name dialog box while creating
a formula by selecting the Insert menu, the Name command
and the Paste command.
φ Step-by-Step
Use a range name in a formula.
Practice the Concept: Select cell I5, type =E5/ and press [F3]. Then select
Qtr1_Total, click OK, and press [Enter] to complete the formula. Copy the formula
to the range I6:I7. Click cells I6 and I7. Notice that the name did not change when you
copied the cell.
δ Discussion
You can create names for rows and columns using text entered into the first or last cell
of the row or the top or bottom cell of the column. This option is a quick way to create
names that correspond directly to worksheet entries. For example, in a worksheet
containing the quantity of products sold each month, you can use the product names in
the row headings to name the rows of quantities sold.
When Excel names rows and columns from headings, it uses the text in the indicated
location (i.e., the top, bottom, right or left cell) to name the selected range. The cells
containing the text are not included in the named ranges. You can create multiple
names at the same time by selecting a range that spans several columns or rows.
φ Step-by-Step
Create range names from headings.
Display the Name Box list on the formula bar; notice that a name was created for each
heading in the range. Select the Feb name. Click any cell to deselect the range.
δ Discussion
After you have named a range, you can use it in existing formulas. For example, after
you have created formulas in a worksheet, you may decide that using names in the
formulas will make it easier for others to analyze the worksheet. Since Excel does not
automatically replace cell references in existing formulas when you assign names, you
must replace the cell addresses in existing formulas with names as desired. This
technique is called applying names.
Names are applied to the current worksheet only. Consequently, you cannot group
worksheets and apply names to multiple sheets at the same time.
φ Step-by-Step
Apply range names to formulas.
Select each cell in the range B8:G8. Notice that the cell addresses have been replaced
by names in each formula.
δ Discussion
You can delete names you no longer use. For example, if you change the name of a
range, you can delete the old name.
φ Step-by-Step
Delete a range name.
Practice the Concept: Notice that the formula in cell G8 now displays an error
message, #NAME?, and the Error Checking button appears. Re-create the range
name Net_Profits for the range G4:G7. Notice that the formula updates.
δ Discussion
A 3-D formula is a formula where cell references refer to cells in more than one
worksheet. In standard 3-D formulas, you must activate each worksheet and select the
cells you want to reference as you are building the formula.
You can use range names as a simple and effective way to create 3-D formulas. Since
names are available to all worksheets in the workbook, you can select names from the
Name Box list or type them into the formula rather than going to each worksheet to
select cell references. This option can save you time and reduce confusion in creating
3-D formulas.
Names are often easier to remember than cell addresses, particularly in a large
worksheet or in multiple workbooks when you cannot see the desired cell.
When using names in formulas, you can either type the name into the formula or
select the name from the Paste Name dialog box. If range names are long, the Paste
Name dialog box helps you avoid typing errors.
φ Step-by-Step
Use range names in a 3-D formula.
Press [F3] to open the Paste Names dialog box and double-click Qtr2_NetProfits to
insert the name. Continue creating the following formula by typing each operator and
using the Paste Name dialog box to insert each name:
=Qtr1_NetProfits+Qtr2_NetProfits+Qtr3_NetProfits+Qtr4_NetProfits
δ Discussion
You can create names that refer to the same range in multiple worksheets. For
example, you can define a name for the same cell address in four different worksheets.
Naming a 3-D range can simplify creating a formula.
φ Step-by-Step
Create a 3-D range name.
δ Discussion
You can use a named 3-D range in a formula just as you would any other named
range. 3-D ranges can save you a significant amount of time. For example, if you have
named the cell containing the quarterly totals in each of four worksheets, you can sum
all four cells using the range name.
φ Step-by-Step
Use a 3-D range name in a formula.
EXERCISE
USING RANGE NAMES
ε Task
Create and use names for ranges.
1. Open Region14.
2. Select the range B4:D8 and create range names for each column
from the column headings.
3. Use the Name Box list to jump to the Mar range.
4. Delete the Jan, Feb, and Mar range names you just created.
5. On the Northeast worksheet, select the range B5:B8 and name it
Jan_NE.
6. Select the range C5:C8 and name it Feb_NE.
7. Select the range D5:D8 and name it Mar_NE.
8. Select cell B9 and create an =SUM formula using the Jan_NE
range.
9. Apply the range names to the formulas in the range C9:D9.
10. Use the Name Box list to jump to the Mar_C range. Notice that the
Central worksheet now appears on the screen.
11. Display the Totals worksheet.
12. Select cell D5 on the Totals worksheet. Create an =SUM formula
using the Mar_C, Mar_NE, and Mar_SE names to add the March
sales in each of the three worksheets. (Hint: Use commas to separate
the names in the SUM function: =SUM(Mar_C,Mar_NE,Mar_SE).)
13. Create a 3-D range name that includes cell E5 in each of the regional
worksheets (i.e., Northeast, Southeast, and Central). Name the
range Week1.
14. Create 3-D range names for cells E6, E7, and E8 in all the regional
worksheets. Name the ranges Week2, Week3, and Week4,
respectively.
15. Go to the By Week sheet, select cell B5, and create an =SUM
function that totals the 3-D range named Week1.
16. Sum the other 3-D range names on the By Week worksheet. Sum
Week2 in cell B6, Week3 in cell B7, and Week4 in cell B8.
17. Close the workbook without saving it.
δ Discussion
Lookup functions look up values in a lookup table and return a result based on those
values. For example, if you need to look up the amount of a health insurance
deduction based on an employee’s salary and type of coverage, you can use a lookup
function to look up the salary and the type of coverage and return the amount of the
deduction.
Before you can use a lookup function, you must create the lookup table elsewhere in
the workbook and enter the desired data. This table must be sorted in ascending order.
There are two lookup functions: vertical and horizontal. The VLOOKUP function
expects the lookup value to be in the first column. The HLOOKUP function expects
the lookup value to be in the first row. The remaining arguments in the lookup
function specify the location of the table of information and the column in which to
find the matching value.
δ Discussion
The VLOOKUP function consists of three required arguments, in the following order:
lookup value, table array, and column index number. The lookup value is the value for
which you want to find matching data and must appear in the first column of the
lookup table; it can be a value, a text string, or a cell reference. The table array is the
name or address of the lookup table. The column index number is the number of
columns Excel must count over to find the matching value.
For example, you may have a parts table consisting of three columns, with the part
numbers in column one and the prices in column three. To look up the price for a
specified part number (lookup value), you would enter a column index value of 3;
Excel would then look for the lookup value in the first column of the parts table and
return the value in the third column of the same row.
You might want to use the lookup table shown below and a column index number of 2
to look up the percent of commission to be paid to a salesperson, based on various
sales levels. For example, if the sales figure you want to look up is 6000, the
commission would be 6%; Excel finds the lookup value (6000) in the first column and
returns the value in the second column of the same row.
A B
1 SALES COMMISSION
2 1000 1%
3 2000 2%
4 3000 3%
5 4000 4%
6 5000 5%
7 6000 6%
8 7000 7%
9 8000 8%
The VLOOKUP function also has a optional fourth argument, range lookup, which
can be either TRUE or FALSE. If the range lookup argument is FALSE, VLOOKUP
will find only exact matches. If the range lookup argument is TRUE, or if a range
lookup argument is not entered, VLOOKUP can find approximate matches. In this
case, the lookup table must be sorted in ascending order by the first column in it;
otherwise VLOOKUP may not return the correct value.
If the range lookup argument is TRUE or omitted and the lookup value does not
appear in the first column of the lookup table, but falls between two values in it, Excel
will use the lower of the two values. If the lookup value is smaller than any value in
the first column of the lookup table, Excel returns an error message.
For example, using the lookup table shown above and a column index number of 2, if
the sales figure you look up is 5700, the commission would be 5%. Since Excel
determines that 5700 is located between the numbers 5000 and 6000, it returns the
value in the second column of the same row as the lower number.
φ Step-by-Step
From the Student Data directory, open SALES72.XLS.
Use the VLOOKUP function.
Select prices from the Name Box (to the left of the formula bar) to view the lookup
table.
Notice that the returned price ($63.99) is the same as the price in the lookup table for
part ST-2472 (cell B21).
Copy the formula to the range C6:C13. Then, click anywhere in the worksheet to
deselect the range.
δ Discussion
The HLOOKUP function consists of three required arguments, in the following order:
lookup value, table array, and row index number. The lookup value is the value for
which you want to find matching data and must appear in the top row of the lookup
table; it can be a value, a text string, or a cell reference. The table array is the name or
address of the lookup table. The row index number is the number of rows Excel must
count down to find the matching value.
For example, you might have a lookup table consisting of two rows, with the total
order amount in the top row and the corresponding shipping charge in the second row.
To look up the shipping charge for a specified order amount (lookup value), you
would enter a row index value of 2; Excel would then look for the lookup value in the
top row of the lookup table and return the value in the second row of the same
column.
You might want to use the lookup table shown below and a row index number of 2 to
look up the percent of commission to be paid to a salesperson, based on various sales
levels. For example, if the sales figure you want to look up is 6000, the commission
would be 6%; Excel finds the lookup value (6000) in the top row and returns the value
in the second row of the same column.
A B C D E F G H
1 1000 2000 3000 4000 5000 6000 7000 8000
2 1% 2% 3% 4% 5% 6% 7% 8%
The HLOOKUP function also has a optional fourth argument, range lookup, which
can be either TRUE or FALSE. If the range lookup argument is FALSE, HLOOKUP
will find only exact matches. If the range lookup argument is TRUE, or if a range
lookup argument is not entered, HLOOKUP can find approximate matches. In this
case, the lookup table must be sorted in ascending order by its top row; otherwise
HLOOKUP may not return the correct value.
If the range lookup argument is TRUE or omitted and the lookup value does not
appear in the top row of the lookup table, but falls between two values in it, Excel
uses the lower of the two values. If the lookup value is smaller than any value in the
top row of the lookup table, Excel returns an error message.
For example, using the lookup table shown above and a row index number of 2, if the
sales figure you look up is 5700, the commission would be 5%. Since Excel
determines that 5700 is located between the numbers 5000 and 6000, it returns the
value in the second row of the same column as the lower number.
ο You can use the Options button in the Sort dialog box to sort
a range by row.
φ Step-by-Step
Use the HLOOKUP function.
Select shipping from the Name Box (to the left of the formula bar) to view the lookup
table.
Notice that since the lookup value ($639.90) is between two values in the lookup
table, the returned cost ($50.00) is the same as the cost for the lower amount ($400),
in cell G18.
Copy the formula to the range F6:F13. Click anywhere in the worksheet to deselect
the range.
δ Discussion
Logical functions make decisions based on criteria. If the criteria evaluate to true, one
action is taken; if the criteria evaluate to false, a different action is taken.
The IF function returns one value if a condition is true and another value if a condition
is false. In the example above, if the value of the goods shipped is greater than the
specified amount, a true value would be returned. If the shipped value is less than the
specified amount, a false value would be returned.
You can also use the IF function to display text as a result of a logical test, but you
must enclose the text you want to display in quotation marks.
Component Description
logical test The test condition. It can contain cell references, text in
quotes, cell names, and numbers. The items are
compared using the following comparison operators:
= equal to
<> not equal to
> greater than
>= greater than or equal to
< less than
<= less than or equal to
Component Description
value if true The desired result if the logical test is true. It can be a
number, formula, cell reference, cell name, text in
quotes, or another function.
value if false The desired result if the logical test is false. It can be a
number, formula, cell reference, cell name, text in
quotes, or another function.
IF Function Result
=IF(B7>10,C7*.1,0) If the number in cell B7 is greater
than 10, multiply the number in cell
C7 by .1; otherwise, return the
number 0
=IF(B7<=10,C7*.1,D7*.1) If the number in cell B7 is less than
or equal to 10, multiply the number
in cell C7 by .1; otherwise, multiply
the number in cell D7 by .1
=IF(B7<>10,"GOOD","") If the number in cell B7 is not equal
to 10, enter the text GOOD in the
current cell; otherwise, leave the cell
blank
=IF(B7="BONUS",C7+1000,C7) If cell B7 contains the text BONUS,
add 1000 to the number in cell C7;
otherwise, enter the contents of cell
C7
Creating an IF function
φ Step-by-Step
Use the IF function.
Notice that since the first quarter sales total for Smith, S. was below his quota, a zero
(0) was entered as his bonus.
Copy the formula to the range G9:G13. Then, click anywhere in the worksheet to
deselect the range.
δ Discussion
You can use an IF function within another IF function to create a nested IF function.
A nested IF function allows you to test for a second condition if the first condition is
found false. For example, an IF function could test whether or not a number is equal
to 1. If false, another IF function within the first could test whether or not the number
is equal to 2.
φ Step-by-Step
Use nested IF functions.
Copy the formula to the range J9:J13. Then, click anywhere in the worksheet to
deselect the range.
δ Discussion
Depending upon the circumstances, a function may return an error message instead of
performing the desired calculation. For instance, a function that averages a range will
return a #DIV/0! error message if the range contains no data. The ISERROR function
is commonly used within an IF function to handle errors messages returned by a
formula.
The ISERROR function tests TRUE if any of the following error messages are
returned by a formula: #N/A, #VALUE, #REF, #DIV/0!, #NUM, #NAME?, or
#NULL. It tests FALSE if anything other than an error message is returned.
The ISERR function is similar to the ISERROR function, except that it does not
respond to the error value #N/A.
The syntax of these functions is as follows, where (value) is a cell reference or range
name:
ISERROR(value)
ISERR(value)
φ Step-by-Step
Use the ISERROR function in an IF function.
The formula returns the text no data instead of the error message. Copy the formula
to the range G15:I15. Then, type 50,000 in cell F8 and press [Enter]; notice that the
message in cell F15 changes.
δ Discussion
You can use AND conditions to test multiple criteria in IF functions. For example,
you may want to give a salesperson a $500 bonus if he or she produces $10,000 in
sales and has at least five years experience. This example represents an AND
condition. When used in an IF function, an AND condition returns a TRUE value if
both arguments are true and a FALSE value if either argument is false.
φ Step-by-Step
Use an AND condition in an IF function.
Copy the formula to the range D9:D13. Then, click anywhere in the worksheet to
deselect the range.
δ Discussion
You can use OR conditions to test multiple criteria in IF functions. For example, you
may want to give a salesperson a $500 bonus if he or she produces $10,000 in sales or
if he or she has at least five years experience. This example represents an OR
condition. When used in an IF function, the OR condition returns a TRUE value if
either argument is true and a FALSE value if both arguments are false.
φ Step-by-Step
Use an OR condition in an IF function.
Copy the formula to the range E9:E13. Then, click anywhere in the worksheet to
deselect the range.
δ Discussion
When you enter a number into an Excel worksheet, Excel can store it with up to 15
digits. Although you can format numbers so that Excel rounds off extra decimal
places, Excel uses all decimal places in calculations. This feature can lead to some
calculations appearing incorrect.
Rounding a number is different than formatting a number. When you round a number
to a certain number of decimal places, the extra decimal places are removed and all
calculations are performed using the rounded value.
ROUND(number,number of digits)
The number argument can be a value or a cell address. The number of digits argument
determines the precision of the rounded number. A positive number of digits argument
returns an equal number of decimal places. If the number of digits argument is 0,
Excel rounds to the next whole number. A negative number of digits argument rounds
exponentially to the next ten, hundred, thousand, etc.
Some examples of the ROUND function are listed in the following table:
φ Step-by-Step
Use the ROUND function.
Notice that the number in cell G7 differs from that in cell E7 because it is based on the
rounded number in cell F7. Then, copy the formula to the range F8:F12.
Select the range D7:D12 and click the Decrease Decimal button on the Formatting
toolbar twice to format the numbers for four decimal places. Notice that the values in
column E do not change; the calculations are still based on the full number of decimal
places. Use the Undo feature twice to remove the formatting.
δ Discussion
In order to calculate a worksheet using the numbers as they are displayed, you can
limit the precision of formatted numbers. Limiting the precision changes the actual
values in the worksheet to their formatted versions. For example, if a cell containing
an actual value of 123.4567 is formatted with no decimal places, only 123 will
display. In a calculation, however, Excel will still use 123.4567 (the entire number,
including all decimal places). If you limit the precision of the cell to the formatted
value, Excel will use only the formatted value (123) in calculations and will actually
remove all decimal places in the stored number.
φ Step-by-Step
Limit the precision of numbers.
Select cell C7. Notice that, although the salary displayed on the worksheet is 4975, the
actual value in the cell is 4974.554. All the salaries in column C have three or more
decimal places, even though the decimal places do not appear due to the cell
formatting.
Select each of the cells in column C, one at a time. Notice that the decimal places have
been removed.
Close SALES72.XLS.
EXERCISE
USING ADVANCED FUNCTIONS
ε Task
Use advanced functions in a workbook.
1. Open Functex.
2. Display the Hours worksheet, if necessary.
3. Select cell F6 and use the VLOOKUP function to calculate the pay
rate for full-time, part-time, or overtime work, according to job type.
(Hint: The lookup value is the Job Type in C6, the lookup table is
named table, and the column index number is the Type of Time in
E6.)
4. Copy the formula to the range F7:F12.
5. Display the Sales-Previous worksheet.
6. Customers get free shipping if their average sales are more than
20,000. In cell I5, use an IF function to test the average sales. If the
average sales (H5) are greater than or equal to 20,000, Yes should
appear in the cell; otherwise, No should appear in the cell. (Hint: Do
not add a comma in 20000.)
7. Copy the formula to the range I6:I13.
8. The customer discount depends on the customer status. In cell J5, use
a nested IF function to determine the correct discount for each
customer according to the following table. (Hint: Test to see if the
status in cell B5 is a 1, 2, or 3; otherwise, a discount of 10% is
entered.)
Status Discount
1 0%
2 5%
3 7.5%
4 10%
δ Discussion
You can use a data table to vary one or two values in a formula and display all
possible results in a table format. For example, you can use a data table to display all
possible projected sales based on total sales and various growth percentages.
To create a data table, you must first indicate the input cells (the cells containing the
variable values in the formula). In the previous sales growth example, the input cells
are the cells containing the total sales and those containing the percentage growth
figures. The input values are then substituted in the formula and the result of each
calculation is placed into an output cell in the data table.
δ Discussion
When you create a data table, the placement of the formula used in the calculation
varies, depending on the type of data table you are creating.
If a one-variable data table is arranged in columns, the formula used in the calculation
is placed in the cell at the top of the output column. In the following diagram, column
B is the output column and the formula must be placed in cell B1.
A B
1 FORMULA
2 25.67
3 12.50
4 35.42
5 97.16
A one-variable data table arranged in columns
If a one-variable data table is arranged in rows, the formula is placed in the cell to the
left of the output row. In the following diagram, row 2 is the output row and the
formula must be placed in cell A2.
A B C D E
1 25.67 12.50 35.42 97.16
2 FORMULA
A one-variable data table arranged in rows
In a two-variable data table, both rows and column are used for input data, and the
formula used in the calculations must be placed above the column input cells and to
the left of the row input cells. In the following diagram, column A contains one set of
variable input values and row 1 contains the other set of input values. Therefore, the
formula must be placed in cell A1.
A B C D E
1 FORMULA 25.67 12.50 35.42 97.16
2 5
3 10
4 15
5 20
A two-variable data table
δ Discussion
When you create a one-variable data table, you can enter the input values either across
a row or down a column.
If the one-variable data table consists of two columns, the first column is the input
column and contains all possible values for the variable. The second column is the
output column. In addition, the cell directly above the output column must contain the
formula used in calculating the data table.
If the one-variable data table consists of two rows, the top row is the input row, the
second row is the output row, and the cell to the left of the output row must contain
the formula.
The input cell is critical when creating a data table. It is the cell containing the
variable value and must be included in the formula. As the variable values are entered
into the data table, the result of each calculation appears in the corresponding cell in
the output column.
φ Step-by-Step
From the Student Data directory, open WHATIF1.XLS.
Create a one-variable data table.
Practice the Concept: Select cell A2, type 159.99, and press [Enter]. Notice that the
data table recalculates.
δ Discussion
You can create a two-variable data table that evaluates two different values in a
formula. A two-variable data table uses both an input column and an input row. The
input row is the first row and the input column is the first column in the data table.
You enter the formula you want to calculate in the cell above the input column and to
the left of the input row.
A two-variable data table references two input cells: one for column input data and
one for row input data; both input cells must be included in the formula. The formula
calculates each of the possible combinations of the row and column input cells and
places the results in the corresponding, intersecting cell in the data table.
φ Step-by-Step
Create a two-variable data table.
Display the Two Variables worksheet. Notice that the unit prices of several items are
listed across row 5 and that a list of increasing quantities appears down column A.
Practice the Concept: In cell D5, type 85.12 and press [Enter]. (Adjust the column
width, if necessary, to view the values.) Notice that Excel recalculates all the values in
column D, based on the new input value.
Close WHATIF1.XLS.
EXERCISE
USING DATA TABLES
ε Task
Create one-variable and two-variable data tables.
1. Open Commrate.
2. In cell B5, enter a formula to multiply the Unit Price value in cell
A2 by the Quantity value in cell B2.
3. Create a one-variable data table in the range B4:G5. (Hint: The row
input cell is the quantity in cell B2.)
4. In cell A11, enter a formula that multiplies the sales figure in cell A8
by the commission rate in cell B8.
5. Create a two-variable data table in the range A11:G16. (Hint: The
row input cell is cell B8 and the column input cell is cell A8.)
6. Close the workbook without saving it.
• Run a macro
DEFINING MACROS
δ Discussion
A macro is a program you can create to automatically perform frequently used
operations. It contains all the commands, mouse movements, and user actions
necessary to complete a task. Macros can save you considerable time because you can
use them to automate repetitive, time-consuming tasks. You can use macros for
simple tasks you perform frequently or for complex tasks that require consistency.
Excel macros are written in the Visual Basic for Applications programming language.
The series of commands used in a macro is known as a procedure. Each procedure is
given a name that is used to execute the macro.
Each procedure is saved in a device called a module. This module is attached to the
worksheet in which the macro is stored. A module is hidden and cannot be seen in the
normal window view. You must use the Visual Basic Editor to select a module in
order to view and edit the macro commands.
All procedures begin with the word Sub, followed by the name of the macro and an
open and a closing parenthesis, and end with the words End Sub. Commands entered
between these two lines are macro statements. When you record a procedure, Visual
Basic translates the menu choices and keystrokes into the macro statements.
Comments may also be inserted into a procedure to add clarity. If you know Visual
Basic, you can write a procedure yourself instead of using the macro recorder.
δ Discussion
When you open a workbook containing macros, you could unknowingly install a virus
on your computer. A virus is a type of macro that is self-activated when a workbook is
opened. It can invade your computer and be stored in hidden fashion in one or all of
Excel provides protection against such incidents. A Microsoft Excel warning box
opens if a workbook containing macros is opened. This warning box gives you a
number of choices. If you can verify the source of the macros, you can enable them
and open the workbook without risking exposure to a virus. If you are not sure of the
source of the macros, you can disable the macros before you open the workbook and
then verify the macros later.
You can choose how you want Excel to respond to macros on the Security Level page
in the Security dialog box, which is accessed from the Security page in the Options
dialog box. A High security setting is the default and will only enable macros from a
list of trusted sources. If you select a Low security setting, workbooks containing
macros will open without a prompt. A Medium security setting will prompt you to
enable or disable the macros.
φ Step-by-Step
Open a workbook containing macros.
RUNNING A MACRO
δ Discussion
Macros are saved in modules, and both are saved with the workbook in which they
were written. Before you can run a macro, the workbook in which it is saved must be
open. When you select a macro from the Macro dialog box, Excel performs its
commands in sequence.
Macros in any open workbook can be run from any other open workbook.
Running a macro
ο You can also run macros by clicking the Run Macro button
on the Visual Basic toolbar.
φ Step-by-Step
Run a macro.
The macro used in the following step-by-step does not contain a file path. As a result,
it will look in the folder that contains the City56.xls data file. Make sure that your
current folder is set for the path containing the student data files.
δ Discussion
Excel performs macro commands in sequence. If a macro has a shortcut key assigned
to it, you can run the macro by pressing the shortcut key. A shortcut key consists of
pressing the [Ctrl] key and a key assigned to the macro. If an uppercase letter has
been assigned, you need to press the [Ctrl] key, the [Shift] key, and the letter
assigned to the macro.
φ Step-by-Step
Use a shortcut key to run a macro.
The macro used in the following step-by-step does not contain a file path. As a result,
it will look in the folder that contains the City56.xls data file. Make sure that your
current folder is set for the path containing the student data files.
δ Discussion
The Visual Basic toolbar provides a variety of buttons that can be used when creating,
editing, or running macros.
The Run Macro button opens the Macro dialog box, so that you can run a macro. The
Record Macro button allows you to record a macro. The Visual Basic Editor button
opens the Visual Basic Editor window, in which you can edit an existing macro.
Since macros can transmit viruses, you can use the Security button to set the security
level you want to employ when opening workbooks containing macros.
Other buttons are used for automating forms and working with HTML tags and scripts
for workbooks saved as Web pages.
φ Step-by-Step
Use the Visual Basic toolbar.
Make sure that your current folder is set for the path containing the student data files.
Run the Atlanta macro and then close the Atlanta workbook.
δ Discussion
Excel macros are written in the Visual Basic for Applications (VBA) programming
language. Macros are saved in modules, which in turn are saved in the worksheet in
which the macros were written. Modules cannot be viewed in the normal window
view; they can only be displayed in the Visual Basic Editor window. You can view,
edit, and run macros from this window.
The Visual Basic Editor window houses three smaller windows. The upper left
window is the Project Explorer window. It displays the various worksheets and
modules in folder and file format. These folders, worksheets, and modules can be
displayed or hidden in much the same way as files and folders are displayed or hidden
in Windows Explorer.
The lower left window is the Properties window. It displays the properties of the
worksheet or module selected in the Project Explorer window.
The large window at the right is the Code window. It displays the contents of the
worksheet or module selected in the Project Explorer window. For example, when a
module is selected, the entire procedure, including the header, footer, macro name,
macro code, and comments, appears in the Code window. You use the Code window
to display, edit, and run macros.
ο To open the Code window, select the View menu and the
Code command.
φ Step-by-Step
Open the Visual Basic Editor window.
If necessary, enable the macros and display the Visual Basic toolbar.
Practice the Concept: If necessary, maximize the Code window. Press [Alt+F11] to
switch to the Excel window. Then, display the Visual Basic Editor window again.
δ Discussion
The Visual Basic Editor window displays the Project Explorer window, the Properties
window, and the Code window. Each of these windows can be opened and closed
independently. When a closed window is reopened, it opens in its previous size and
location.
ο You can also press the [Ctrl+R] key combination to open the
Project Explorer window, the [F4] key to open the Properties
window, and the [F7] key to open the Code window.
φ Step-by-Step
Use the Visual Basic Editor window.
If necessary, enable the macros and open the Visual Basic Editor window.
Notice that the module contains two macros, NewYork and Atlanta, which open
NEWYORK.XLS and ATLANTA.XLS respectively.
Close the Visual Basic Editor window and hide the Visual Basic toolbar.
Close CITY56.XLS.
EXERCISE
USING MACROS
ε Task
Use macros in a workbook.
• Delete a macro
Lesson 6 - Recording Macros Excel XP Level 4
RECORDING A MACRO
δ Discussion
A macro can be created using the macro recorder. Excel records the macro as you
perform the steps you want to include in it. The steps you perform are not recorded as
simple keystrokes, however; they are translated into the Visual Basic for Application
programming language, which translates your steps into macro statements.
When you record a macro, Excel creates a module in the current worksheet. As you
perform the macro keystrokes, they are saved as Visual Basic language statements in
the module. A module can contain more than one macro.
During the macro recording process, you name the macro and enter descriptive
information about it. This information is entered into the Record Macro dialog box
and appears as a comment in the module.
In addition to naming the macro, you can select the location where you want to store
the macro. Macros can be stored in the current workbook, a new workbook, or the
Personal Macro Workbook. Macros stored in a workbook are only available when that
workbook is open. If you store a macro in the Personal Macro Workbook, however, it
will be available to all workbooks.
ο You can also record a macro by selecting the Tools menu, the
Macro submenu, and then the Record New Macro command.
φ Step-by-Step
From the Student Data directory, open CITY57.XLS.
Record a macro.
If necessary, enable the macros and display the Visual Basic toolbar.
Make sure that your current folder is set for the path containing the student data files.
Close the Chicago workbook. Then, open the Visual Basic Editor window and view
the macro by double-clicking Module2 in the Project Explorer window. Notice that
the macro also recorded the path to the Chicago workbook. Close the Visual Basic
Editor window.
Use the [Ctrl+e] shortcut key to run the Chicago macro. Then, close the Chicago
workbook.
δ Discussion
You can assign a shortcut key to a macro, either when you create the macro or after
the macro has been created. After a shortcut key has been assigned to a macro, the
macro runs whenever the shortcut key is pressed. All macro shortcut keys must begin
with the [Ctrl] key followed by any character or with the [Ctrl+Shift] key
combination followed by any character.
If you assign a shortcut key while the macro is being created, it appears as a comment
in the module. When a shortcut key is assigned to an existing macro, this comment is
not automatically created. You can edit the macro text, however, to manually add the
comment.
ξ You should avoid assigning macro shortcut keys that are the
same as the standard Excel shortcuts (e.g., [Ctrl+B],
[Ctrl+S]), because the standard Excel shortcut will be
overridden by the macro shortcut.
φ Step-by-Step
Assign a shortcut key to a macro.
If necessary, enable the macros and display the Visual Basic toolbar.
The macro used in the following step-by-step does not contain a file path. As a result,
it will look in the folder that contains the City57.xls data file. Make sure that your
current folder is set for the path containing the student data files.
Use the [Ctrl+a] shortcut key to run the Atlanta macro. Then, close the Atlanta
workbook.
δ Discussion
Absolute and relative references refer to how a macro records cell locations. When
you use absolute references while recording a macro, Excel records absolute, or exact,
cells references. For example, if you enter the label Annual Sales Report in cell A4
while recording a macro with absolute references, that label will always appear in cell
A4 whenever you run the macro, no matter which cell is active.
When you use relative references while recording a macro, Excel records cell
references relative to the active cell. For example, if you type the label Annual Sales
Report in the cell to the left of the active cell while recording a macro with relative
references, that label will always be entered into the cell to the left of whichever cell is
active when you run the macro. Relative references give a macro more flexibility.
φ Step-by-Step
Use relative references to record a macro.
If necessary, enable the macros and display the Visual Basic toolbar.
Format the current cell with italics and a font size of 14. Then, type Worldwide
Sporting Goods into the current cell and press [Enter].
Return to the table and continue on with the next step (step 8).
Clear the format and contents of cell A14 by selecting cell A14, selecting the Edit
menu, pointing to the Clear command, and selecting the All command. Then, select
cell A1 and run the Company macro to test it.
Open the Visual Basic Editor window. Display the Company macro in the Module2
module. Then, close the Visual Basic Editor window.
δ Discussion
You can assign a macro to a menu. The macro appears as a command on the selected
menu, and you can give it any name you want.
The macro command appears on the menu whether or not the workbook containing
the macro is open. You can execute the macro with any workbook, just as you can
execute any standard menu command. If the workbook containing the macro is not
open when you execute the command, Excel will automatically open it and then run
the macro.
To use the keyboard to select a menu command, you can type an ampersand (&)
before the letter you want to be underlined. For example, &Report appears as Report
on the menu and Re&port appears as Report. You can then display the menu and
press the underlined letter to run the macro.
ο You can move the Customize dialog box as needed to drag the
Custom Menu Item command from the Commands list to
the desired location on a menu.
φ Step-by-Step
Assign a macro to a menu.
Save the City57 workbook and then close it. Create a new workbook. Then, select the
View menu and the Company Name command. Enable the macros. Notice that Excel
opens the file in which the Company macro is stored to access it.
Close the new workbook without saving it; leave the City57 workbook containing the
Company macro open.
δ Discussion
Once a macro has been assigned to a menu, it is available to all worksheets.
If you no longer want the macro to appear on the menu, you can remove the custom
menu item from the menu.
φ Step-by-Step
Remove a custom menu item from a menu.
DELETING A MACRO
δ Discussion
If you no longer use a macro, you can delete it. Since macros can invoke other
macros, you should make sure that the macro you are deleting is not needed by
another macro.
If a macro is stored in a workbook, the workbook must be open in order to delete the
macro. If the macro is stored in the Personal Macro Workbook, which automatically
loads as a hidden window every time you open Excel, the Personal Macro Workbook
window must be unhidden before the macro can be deleted.
ο You can also open the Macro dialog box by selecting the
Tools menu, pointing to the Macro command, and selecting
the Macros command.
φ Step-by-Step
Delete a macro.
If necessary, enable the macros and display the Visual Basic toolbar.
EXERCISE
RECORDING MACROS
ε Task
Record macros.
δ Discussion
New macros can be created by recording the steps or typing the commands directly
into the Code window in the Visual Basic Editor. To write a new macro in the Visual
Basic Editor Code window, you must type the word Sub, followed by the macro name
and a set of parentheses ( ( ) ). Excel automatically supplies the End Sub command.
All steps in the procedure must be entered between the Sub and End Sub commands.
New macros can be inserted in an existing module or added to a new module. You can
insert a macro above or below any existing macro; the position of the macro in the
module does not affect its performance.
φ Step-by-Step
From the Student Data directory, open CITY58.XLS.
Write a new macro.
Open the Visual Basic Editor window and display Module1 in the Code window.
δ Discussion
When macros are first recorded, the recording process documents the name, date, and
other macro descriptions in the Code window. This information appears before the
actual macro statements. If you make a change to a macro, you should go into the
documentation area of the macro and edit this information as necessary. For example,
if you add a shortcut key to a macro after the macro has been recorded, this
information is not automatically added to the macro documentation. You must
manually add a line to document the change.
In longer and more complex macros, you can add comments to the various macro
steps. Comments can explain what a step or series of steps should accomplish. This
information can be helpful if the macro must be modified or debugged at some later
date.
Comments must begin with a single apostrophe ('). Excel treats any line that begins
with a single apostrophe as a comment. Comments can appear either on a separate line
or adjacent to a macro statement. Comments appear in black text when they are
entered and change to green text as soon as you move to another line.
φ Step-by-Step
Enter macro comments.
If necessary, enable the macros, open the Visual Basic Editor window, and display
Module1 in the Code window.
Practice the Concept: Display Module2 in the Code window. In the Company
macro, click in the blank line above the Selection.Font.Bold = True command. Type
an apostrophe ('), a space, and the following comment: Formats the current cell.
Press [Enter].
Scroll as necessary and click at the end of the End With command in the same macro;
press [Enter] to add a new line. Then, type the following comment: ' Inserts the
company name. Remove the spacing to the left of the apostrophe. Click in the next
line to see the comment color change to green.
δ Discussion
There may be times when you want to combine macros for a more efficient operation.
For example, if three different macros each open one of three separate workbooks,
you can combine the three macros into one to open all three workbooks in one step.
You can combine macros by copying and pasting the command statements from one
macro to another. Macro commands can be copied from other macros, other modules,
or even other workbooks.
Copying macro commands saves the time it takes to re-record a macro or to write one
or more new macro steps.
φ Step-by-Step
Copy macro commands between modules.
If necessary, enable macros, open the Visual Basic Editor window, open Module1 in
the Code window, and display the NewYork macro.
Make sure that your current folder is set for the path containing the student data files.
Practice the Concept: Copy the step in the Atlanta macro that opens the Atlanta
workbook and paste it into the Open_Cities macro, on a line below the step that
opens the Newyork file. Then, open Module2 in the Code window and copy the step
in the Chicago macro that opens the Chicago workbook and paste it into the
Open_Cities macro, on a line below the step that opens the Atlanta file. All three
macro commands should appear above the End Sub command.
Close the Visual Basic Editor window. Run the Open_Cities macro. Then, run the
Close_Cities macro to close the Newyork, Atlanta, and Chicago workbooks.
δ Discussion
Depending on the changes you need to make, it may be easier to edit the macro text
rather than to delete the entire macro and record it again. You can use standard editing
techniques to edit macro text.
φ Step-by-Step
Edit macro commands manually.
If necessary, enable the macros and display the Visual Basic toolbar.
Make sure that your current folder is set for the path containing the student data files.
Practice the Concept: Open Module2. Scroll as necessary to view the Close_Cities
macro. Replace the word NEWYORK with tampa in the first Workbooks().Close
command.
Close the Visual Basic Editor window and run the Open_Cities macro. Notice that
the macro now opens the Tampa workbook instead of the Newyork workbook.
δ Discussion
In addition to recording macro commands, you can also type them directly into a
macro procedure. Macro procedures work with statements and objects. Some macro
steps, such as macro statements, cannot be recorded. For example, you may want to
create a condition that executes specific macro commands if the condition is true and
other commands if the condition is false.
Objects are the elements upon which the macro acts, such as a workbook, worksheet,
range, cell, or chart. A collection is a set of multiple objects. The worksheets in a
workbook are part of a collection. You use VBA (Visual Basic for Applications)
commands to change the properties of an object or collection or to apply a method
(action) to an object. The properties and methods differ depending upon the object.
When entering a command, you must use the proper syntax. The syntax of a command
is the structure of its elements. As you type commands in the Visual Basic Editor, lists
with available properties or methods may appear.
There is often more than one way to perform the same action. For example, you can
record a macro that deletes the contents in the range A6:F12 in the Sales worksheet.
The steps could be recorded using the following selection methods since you would be
manually selecting the worksheet and range.
Sheets(“SALES”).Select
Range(“A6:F12”).Select
Selection.ClearContents
You can accomplish the same result by writing a command, such as the one shown
below, that applies a method to the specified object. The object is the range A6:F12 in
the Sales worksheet. The command assumes that the correct workbook is open and
can be written without the Worksheets property if the command to activate the
worksheet was issued in a previous step.
Worksheets(“SALES”).Range(“A6:F12”).ClearContents
If a group of commands can be recorded, it might be easier to record the macro steps
in a separate macro and then copy and paste them into the larger macro than it would
be to write them directly into the Code window.
φ Step-by-Step
From the Student Data directory, open CITY59.XLS.
Type a macro command.
If necessary, enable the macros, open the Visual Basic Editor window, open the
Module1 module, and scroll as necessary to display the Open_Cities macro.
Make sure that your current folder is set for the path containing the student data files.
Press [Alt+F11] to switch to the worksheet window. Run the Open_Cities macro.
When the macro ends, the City59 workbook should be active. Then, run the
Close_Cities macro. All workbooks should close, except the City59 workbook.
δ Discussion
During the editing process, a macro can be run directly from the Visual Basic Editor
using the Run Sub/UserForm button or the Run Sub/UserForm command on the
Run menu.
If you use the Run menu, you must position the insertion point in the Code window,
within the text of the macro you want to run. Otherwise, the Macro dialog box will
open and you must select and run the desired macro.
ο You can also run a macro directly from the Visual Basic
Editor by pressing the [F5] key.
φ Step-by-Step
Run a macro from the Code window.
If necessary, enable the macros, open the Visual Basic Editor window, and open
Module3.
Close the Visual Basic Editor window. Notice the consolidated data in the City59
workbook.
Notice the consolidated value in cell C6 of $10,703. Open the Atlanta workbook and
change cell C7 from 3250 to 9250; then, close and save the Atlanta workbook. Run
the Urban_Update macro from the City59 workbook window; notice that the
consolidated value in cell C6 changes to $16,703.
EXERCISE
EDITING MACROS
ε Task
Edit macros with the Visual Basic Editor.
11. Run the Sort_RegionLastN macro from the Visual Basic Editor
window. (Hint: Make sure to click anywhere in the macro text
before running the macro.)
12. Close the Visual Basic Editor window.
13. Notice that the list in the Exer83 workbook window is now sorted
first by region and then by last name. Switch to print preview; notice
the landscape page orientation. Then, close print preview.
14. Hide the Visual Basic toolbar.
15. Close the workbook without saving it.
δ Discussion
You can create a custom toolbar in Excel. This option allows you to group buttons
you use regularly on one toolbar.
Custom toolbars are not saved with any particular workbook; rather they are saved to
the Excel application itself. As a result, a custom toolbar is available at any time, with
any workbook.
The custom toolbar name appears on the toolbar shortcut menu, as well as on the
Toolbars page in the Customize dialog box.
φ Step-by-Step
From the Student Data directory, open MAC8.XLS.
Create a custom toolbar.
δ Discussion
Once you have created a custom toolbar, you can add buttons to it. Many more
buttons are available than those you see on the built-in toolbars.
All available buttons are listed on the Commands page in the Customize dialog box.
When the Customize dialog box is open, any of these buttons can be added, edited,
deleted, or moved. In order to add a button to a toolbar, the toolbar must be displayed.
The Description button on the Commands page displays the ScreenTip for the
selected button.
φ Step-by-Step
Add or remove a toolbar button.
If necessary, open the Customize dialog box and display the My Toolbar toolbar.
Practice the Concept: Scroll as necessary and add the Print button from the File
category to the My Toolbar toolbar.
δ Discussion
All the categorized commands in the Commands list box in the Customize dialog box
have commands attached to them, except for those in the Macros category. You can
add the Custom Button command in the Macros category to a toolbar and then attach
the desired command (usually a macro) to the custom button.
φ Step-by-Step
Add the Custom Button command to a toolbar.
If necessary, open the Customize dialog box, and display the Commands page and
the My Toolbar toolbar.
δ Discussion
Once a custom button has been added to a toolbar, you must assign a command to it.
Usually, the command you assign is a macro. Once assigned, the macro will run
whenever the button is clicked.
Since toolbars are saved with Excel rather than with any particular workbook, the
commands on a custom toolbar are available to all workbooks. If you assign a macro
stored in a workbook to a custom button, the macro executes only when the workbook
containing the macro is open. If the workbook containing the macro is closed when
you click the custom button, Excel will automatically open it in order to run the
macro, prompting you to enable the macros in it, if necessary.
φ Step-by-Step
Assign a macro to a custom button.
If necessary, open the Customize dialog box, and display the Commands page and
the My Toolbar toolbar.
Close the Customize dialog box. Then, select cell A5 and click the custom button on
the My Toolbar toolbar. Notice that the macro inserts today’s date into the selected
cell.
δ Discussion
When a custom button has been added to a toolbar, its default button image appears
on the toolbar. You may, however, want the button image to be easily recognized or to
reflect the action the macro executes.
You can easily change a button image; Excel provides numerous images from which
you can choose. In addition, you can edit an existing button image as desired.
φ Step-by-Step
Change a button image.
Open the Customize dialog box and display the Commands page.
δ Discussion
By default, a toolbar button displays only the button image. You can display text as
well to better identify a button, or you can display only button text and no image.
Displaying button text can be especially helpful to someone unfamiliar with the
default button images, or if you have added numerous custom buttons to custom or
default toolbars.
φ Step-by-Step
Display both button text and image.
If necessary, open the Customize dialog box, and display the Commands page and
the My Toolbar toolbar.
δ Discussion
When you create a custom toolbar, it is stored by default in Excel itself, not in any
particular workbook. Therefore, it is available to all workbooks. A custom toolbar
can, however, be attached to a specific workbook as well.
The advantage to attaching a custom toolbar to a workbook is that the toolbar will
always be available to the workbook, regardless of the computer on which you open
it. If you intend to share a workbook or to copy the workbook to another computer, it
is a good idea to attach the custom toolbar so that anyone who opens the workbook
can use it.
After a workbook containing a custom toolbar has been opened on any computer, the
custom toolbar appears in the list of available toolbars for that computer, even when
the workbook is closed.
ο You can use the Attach Toolbars dialog box to attach and
remove custom toolbars from a workbook. The Copy button
changes to a Delete button when you click a custom toolbar in
the Toolbars in workbook list box.
φ Step-by-Step
Attach a custom toolbar to a workbook.
δ Discussion
You can delete a custom toolbar if you no longer use it. Deleting a custom toolbar
completely removes it from Excel. A workbook does not have to be open to delete a
custom toolbar.
Deleting a custom toolbar from Excel, however, does not delete it from any workbook
to which it has been attached. Consequently, if you delete a custom toolbar and then
open a workbook to which it has been attached, the custom toolbar is added to Excel
and is again available to any workbook.
φ Step-by-Step
Delete a custom toolbar.
δ Discussion
You can create one or more custom menus to store commands for commonly-used
tasks. Custom menus allow you to group commands on one menu, instead of having
to use several menus to perform functions.
Like a standard menu, a custom menu displays a list of commands and submenu
commands, if applicable. The first level of a custom menu, the menu name, appears
on the menu bar. A submenu command on any menu displays an arrow to the right of
its name, indicating that there are additional items that appear when the submenu is
selected.
When you create a custom menu, you can add it to the menu bar or any toolbar. You
can also add a custom menu to any standard menu (such as the Tools menu) or
another custom menu.
New menus and submenus are given the default name, New Menu. After a menu
command has been added, you can change its name. You can assign a shortcut key to
a menu name or command by typing an ampersand (&) to the left of the desired
shortcut key; the letter following the ampersand will then be underlined in the menu
name or command.
φ Step-by-Step
Create a custom menu.
Close the Customize dialog box. Select the Open menu; notice that an empty menu
appears.
δ Discussion
After a custom menu has been created, you should add commands to it. You can
assign an existing Word command, a submenu, or a macro to any menu, not just to
custom menus.
You can delete a menu, submenu, or menu command when you no longer need it.
Deleting a menu or submenu deletes all the commands and submenus on it. Deleting a
menu or submenu, however, deletes only the macro commands on it, not the macros
themselves.
φ Step-by-Step
Add menu commands to a custom menu.
Make sure that your current folder is set for the path containing the student data files.
Add the following menu commands to the Open menu and attach the indicated
macros:
Return to the table and continue on with the next step (step 10).
Open the Customize dialog box, delete the Open menu by dragging it off the menu
bar, and then close the Customize dialog box.
Close MAC8.XLS, ATLANTA.XLS, CHICAGO.XLS, and NEWYORK.XLS.
EXERCISE
USING CUSTOM TOOLBARS AND MENUS
ε Task
Work with custom toolbars and menus.
11. Close the Customize dialog box. Test the Regions button on the
Reports toolbar. It should create a regional subtotals report,
formatted with a landscaped orientation. Then, test the SortLN
command; select OK in the Microsoft Excel warning box.
12. Delete the Reports toolbar and the Sort menu.
13. Close the workbook without saving it.
δ Discussion
You can create a button right in your worksheet that will run an associated macro.
Macro buttons can simplify your work, automate repetitive tasks, or help an
inexperienced user perform various worksheet tasks.
You can draw a macro button anywhere on the worksheet, as well as create as many
macro buttons as needed to perform different worksheet tasks.
Like other graphic objects, macro buttons float above the worksheet.
φ Step-by-Step
From the Student Data directory, open CITY60.XLS.
Use a macro button.
The macro used in the following step-by-step does not contain a file path. As a result,
it will look in the folder that contains the City60.xls data file. Make sure that your
current folder is set for the path containing the student data files.
Close ATLANTA.XLS.
δ Discussion
The Forms toolbar is used to create a macro button. After you have drawn the macro
button, you must assign a macro to it. You can then size the macro button and position
it anywhere on the worksheet.
φ Step-by-Step
Create a macro button.
Click the macro button to test it. Notice that the Chicago workbook opens.
δ Discussion
You can create new macro buttons quickly by copying existing ones. This option is
useful in adding several similar macro buttons to a worksheet. When you copy a
macro button, the pasted macro buttons will always be the same size and shape as the
copied macro button.
φ Step-by-Step
Copy a macro button.
Click the New York macro button to test it. Notice that the Newyork workbook
opens.
Close NEWYORK.XLS.
δ Discussion
You can format text on a macro button in much the same way as you format text on a
worksheet. You can select the entire button and apply the same formats to all the
button text, or you can select individual characters in the button text to format.
φ Step-by-Step
Format a macro button.
Practice the Concept: Bold the text on all macro buttons; then, italicize the city
names on each macro button.
δ Discussion
You can move or size a macro button in the same way that you move or size any
graphic object on a worksheet. In order to move or size a macro button, you must first
select it.
ο To select a macro button, hold the [Ctrl] key as you click it;
otherwise, the macro attached to the macro button runs when
you click it.
φ Step-by-Step
Move and size a macro button.
δ Discussion
You can delete any macro button you no longer need. Deleting unused macro buttons
protects you from accidentally running a macro that is outdated or no longer works
correctly.
When you delete a macro button, only the button is deleted; the attached macro
remains intact.
φ Step-by-Step
Delete a macro button.
Close CITY60.XLS.
EXERCISE
CREATING A MACRO BUTTON
ε Task
Create and work with macro buttons on a worksheet.
• Protect a worksheet
• Unprotect a worksheet
• Assign a password
• Remove a password
δ Discussion
You can control access to a worksheet by locking or unlocking individual cells in it. If
worksheet protection is activated, you cannot change the contents of any locked cell.
If you want to allow changes to some cells, however, you can unlock those cells
before you activate worksheet protection.
As a rule, the cells you want to use for data entry are unlocked, and the cells that have
formulas in them are locked so that the formulas cannot be changed. For example, you
can lock all cells in a sales worksheet, except for those cells in which sales figures
need to be entered. You can also lock cells containing text.
Unlocking cells
φ Step-by-Step
From the Student Data directory, open PROJ3.XLS.
Unlock cells in a worksheet.
PROTECTING A WORKSHEET
δ Discussion
Once you have unlocked cells, you can prevent changes to the rest of the worksheet
by protecting it. Protecting a worksheet prevents unauthorized or accidental changes
to formulas. For example, you can unlock only cells E3 and E4, leaving the rest of the
cells in the worksheet locked; if you then protect the worksheet, you will be able to
enter data in cells E3 and E4, but you will not be able to access any other cells.
You can assign an optional password to a protected worksheet. Passwords are case-
sensitive. A password is any combination of letters, numbers, symbols, and spaces,
and can be up to 255 characters long. For example, CLASS is a different password
than class.
You can select what features and functions of the worksheet you want to protect. For
example, you can allow users to select locked or unlocked cells, or format, insert, or
delete cells, columns, and rows.
Protecting a worksheet
φ Step-by-Step
Protect a worksheet.
Select cell D8 and type the word test. A Microsoft Excel warning box opens,
informing you that the cell is protected and you cannot edit it. Close the warning box.
Type 20 in cell E3 and 15 in cell E4. Notice that you can change the content of these
cells since they are unlocked.
UNPROTECTING A WORKSHEET
δ Discussion
You can unprotect a protected worksheet. If you used a password to protect the
worksheet, however, you must know the password to unprotect it.
After you have unprotected the worksheet, you can make changes to any cell in it.
φ Step-by-Step
Unprotect a worksheet.
Select cell D8 and type the word test. Notice that, since the worksheet is now
unprotected, you can type in the cell. Then, delete the word test.
δ Discussion
If you want only certain users to be able to access specified cells in a worksheet, you
can identify those cells as an allow-editing range. You control access to this range by
first locking the cells in it and then assigning a password to it. After activating
worksheet protection, users are prompted for the assigned password when they select
any cell in the allow-editing range. If the correct password is entered, the range is
unlocked for editing; the allow-editing range is not locked again, however, until the
workbook is closed.
ο You can select the allow-editing range before you open the
Allow Users to Edit Ranges dialog box; the range will then
appear in the New Range dialog box when it opens.
φ Step-by-Step
Create allow-editing ranges in a worksheet.
Select cell B4 and type 310853. The Unlock Range dialog box opens with the
insertion point in the Enter the password to change this cell box. Type the password
actuals and select OK to close the dialog box. Then, type 310853 in cell B4. Notice
that you can now edit cell B4 because the allow-editing range has been unlocked.
δ Discussion
When a worksheet no longer needs an allow-editing range, it can be removed from the
worksheet. The worksheet must first be unprotected before you can remove the
unlocked range.
φ Step-by-Step
Delete allow-editing ranges.
δ Discussion
You can protect workbook windows. When you protect a workbook window, the
Minimize, Maximize, and Close buttons are removed; as a result, the window cannot
be moved or resized. This option is useful if you have arranged the windows and want
to prevent them from being rearranged.
You can assign an optional password. Passwords are case-sensitive. For example,
CLASS is a different password than class.
φ Step-by-Step
Protect workbook windows.
Click the workbook Restore Window button to display the current workbook in a
window.
Notice that the Minimize, Maximize, and Close buttons no longer appear on the
workbook window title bar. Try to resize the window by dragging. Notice that you are
unable to perform this task.
δ Discussion
When you unprotect a workbook window, the Maximize, Minimize, and Close
buttons are restored, and the window can be resized. You can also perform structural
changes (such as inserting, deleting, or moving worksheets) in an unprotected
workbook.
If a password has been used to protect a workbook, you must know the password to
unprotect it.
φ Step-by-Step
Unprotect workbook windows.
Notice that the Minimize, Maximize, and Close buttons appear again on the
workbook window title bar. Maximize the window.
ASSIGNING A PASSWORD
δ Discussion
Passwords are used to protect a file. You can assign one password to open a file, and a
different password to modify a file. If you assign both types of passwords to a file,
only those users who know the open password can open the file, and only those users
who know both the open and modify passwords can save changes to it.
Passwords are often assigned to files that contain sensitive data, such as salaries or
bonuses. They can also be used to secure files stored on a network.
Assigning a password
ο You can also use the Security page in the Options dialog box
to assign a password.
φ Step-by-Step
Assign a password to a file.
Close PROJ3.XLS.
δ Discussion
Once a file is password-protected, you must know the password to open it. Whenever
you try to open a password-protected file, the Password dialog box prompts you to
enter the assigned password.
ξ If you forget the assigned password, you cannot open the file.
φ Step-by-Step
Open a password-protected file.
REMOVING A PASSWORD
δ Discussion
If a password is no longer needed, you can remove it from a file. You can then open
the file at any time without a password.
When you remove a password, you must save the file to replace the protected version.
ο You can also use the Security page in the Options dialog box
to remove a password.
φ Step-by-Step
Remove a password from a file.
If necessary, type class in the Password dialog box to open the file.
δ Discussion
When you change any number in a worksheet, all formulas that refer to that number
are automatically recalculated. You can configure the worksheet to recalculate
manually instead. Manual recalculation allows you to change numbers as needed and
then recalculate the worksheet only when desired. This option can save time when you
are working in large, complex worksheets.
When recalculation is set to manual, the Calculate indicator appears on the status bar
when values have changed and formulas need to be recalculated. If the Calculate
indicator appears on the status bar, the worksheet figures may not be accurate. For this
reason, it is a good idea to always recalculate before you print the worksheet.
Calculation options are system settings rather than workbook settings. Consequently,
once you have enabled manual calculation, all worksheets will have to be manually
recalculated until you change the calculation back to automatic.
φ Step-by-Step
Set manual calculation.
Select cell E3, type 25, and press [Enter]. Notice that the formulas do not recalculate
and that the Calculate indicator appears on the status bar.
Press [F9] to recalculate the workbook. Notice that cell B8 changes from 2,140,708 to
2,229,904, cell B10 changes from 1,784,377 to 1,873,573, and the Calculate indicator
no longer appears on the status bar.
δ Discussion
Calculation options are system settings rather than workbook settings. As a result, if
you select manual recalculation for one workbook, you will have to manually
recalculate all workbooks until you change the calculation back to automatic.
φ Step-by-Step
Reset automatic calculation.
Select cell E3, type 15, and press [Enter]. Notice that the formulas recalculate
automatically.
Close PROJ4.XLS.
δ Discussion
Office XP provides a file recovery feature that can recover data lost when an error
prevents the normal saving and closing of a file (such as when your computer
suddenly crashes or loses power). The next time you start Excel after a system halt,
the Document Recovery pane appears on the left side of the application window,
with a list of all workbooks that were open when the error occurred. For each
workbook, the task pane shows the file name, as well as when you last saved the
workbook. If the workbook is marked as recovered, it is probably a more recent
version of the original workbook than the last saved version.
EXERCISE
USING WORKSHEET PROTECTION
ε Task
Use worksheet protection.
1. Open Protect.
2. Unlock the range D6:D12.
3. Protect the worksheet, assigning a password of protect.
4. Change cell D11 to 3. Change cell E11 to 2. Then, close the
Microsoft Excel message box.
5. Unprotect the worksheet. Then, change the type of time in cell E11
to 2.
6. Select the range F6:F12 and make it an allow-editing range. Assign
the password special to the allow-editing range and the password
class to the worksheet.
7. Change the rate in F12 from 5.50 to 6.00. Then, delete the unlocked
range. (Hint: First unprotect the worksheet.)
8. Protect both the workbook structure and windows; assign a password
of workbook. Notice that the window buttons for the workbook are
no longer available.
9. Unprotect the workbook.
10. Assign a password to open the workbook; type save as the password.
Then, close the workbook.
11. Reopen Protect. Notice that you must enter the assigned password.
12. Set the calculation to manual.
13. Select cell D6 and type 7. Then, recalculate the worksheet manually.
Notice that cell G6 is updated.
14. Reset the calculation to automatic.
15. Remove the password from the workbook.
16. Close the workbook without saving it.
3-D ranges
creating, 33
using in formulas, 34, 35
Absolute references
using in macros, 90
Allow-editing ranges
creating, 148, 149
deleting, 151
Arguments
using in functions, 2
Buttons
adding the Custom Button to a toolbar, 116, 117
adding to a toolbar, 115, 116
assigning macros to, 118
changing the image, 119
displaying button text and image, 120, 121
removing from a toolbar, 115, 116
Calculation
automatic, 162
manual, 160, 161
resetting automatic, 162
setting manual, 160, 161
Cells
unlocking in a worksheet, 144, 145
Comments
entering for macros, 101, 102
Data
limiting the precision of numbers, 60, 61
Data tables, 66
creating one-variable, 67, 68
creating two-variable, 69, 70
placing formulas in, 66
Date functions, 10, 11
Dates
formatting, 13, 14
Files
recovering, 163
Financial functions, 3, 4
Formulas
3-D, 31, 32
revising, 15
using 3-D range names, 34, 35
using range names, 24, 25
Functions
date, 10, 11
financial, 3, 4