MIC ROS O F T E X CE L
Table of Contents
Table of Contents .......................................................................................................................1
Find functions quickly with Excel 2002's function search feature .............................................2
Teach your Exce l users not to fear math across the sheets ................................ ......................4
Expand analysis options by importing external data into Excel ................................................8
Teach Excel users to ca lculate elapsed time ........................................................................... 25
Show users how Conditional Formatting can dynamically update their Excel spreadsheets .. 29
Auditing error messages in Excel ................................ ................................ ............................ 34
Save multiple print ranges in Excel.......................................................................................... 37
VB script lets you print the file path in Excel 2000 worksheet footers ..................................... 41
Finding and flagging subsets of Excel records ................................ ................................ ........ 46
Create custom Excel add -ins to save your users time and effort............................................. 49
Track business hours with Excel's WORKDAY function.......................................................... 53
Manage multiple possibilities with Excel scenarios................................................................. 58
Use Excel check boxes to create a list-totaling spreadsheet................................................... 64
Design timesaving Excel sheets with growth in mind.............................................................. 70
Generate random passwords in Excel ..................................................................................... 72
Quickly sort and total your data with Excel’s Data-Subtotals .................................................. 75
Use real -life examples to teach Excel data tables ................................ ................................ .... 84
Teach two-variable Excel data tables with real-life examples .................................................. 92
Teach users to manipulate data with Excel pivot tables .......................................................... 99
Present your Excel data with pivot charts ................................ ................................ .............. 110
Find functions quickly with Excel 2002's function search feature
By Brien Posey
While Excel contains a large assortment of available functions, everything from calculating the inverse
hyperbolic tangent of a number to the interest paid on during a specific period on an investment, but
Excel's function naming scheme can make it difficult to find the function you're looking for. Scrolling
through a long list of sometimes cryptic function names can frustrate even a seasoned Excel user. Luckily
Excel 2002 has made it a little easier to find the function you need with its function search feature.
Suppose you need to calculate a mortgage payment, but have no idea how to do the math. Simply click
Insert | Function to display the Insert Function dialog box, shown in Figure A . Here you will find the
Search for a function text box. Type a brief description of what you are trying to accomplish with the
function and click Go.
Figure A
Excel will provide you with what it believes is the appropriate function(s). For example, if you wanted to
determine a mortgage payment, you could type "How do I calculate a monthly loan payment?" Click Go
and Excel returns two functions—one that calculates the payments for a loan based on constant
payments and a constant interest rate and another that returns the number of periods for an investment
based on periodic, constant payments and a constant interest rate. If you're still not sure which function to
choose or just want more information on a particular function, select the function from the list and click
Help on this function from the bottom of the dialog box. Doing so opens the Excel Help entry for the
function.
Once you choose the function you want to use, Excel 2002 also makes it easier to specify the function's
arguments. When you select the function and click OK Excel displays the Function Arguments dialog box,
shown in Figure B. This box prompts you to enter all the function's required arguments and offers a
description of each argument.
Figure B
Teach your Excel users not to fear math across the sheets
By Jeff Davis | Originally published on TechRepublic March 5, 2003:
http://www.techrepublic.com/article.jhtml?id=r00320030305jed01.htm
Recently a TechRepublic member we’ll call CJ wrote to me asking for help with her budget spreadsheet.
CJ had set up a workbook with four sheets, one sheet for each quarter of 2003. In each sheet, she
entered the dollar amounts budgeted to be spent by each department.
CJ wanted to be able to track the actual amounts someplace and see the differences between budgeted
and actual in another place. I recommended a solution I thought was pretty straightforward:
1.
Make copies of the budgeted sheets, and enter the actual dollars spent in the copies.
2.
Make another set of copies of the original sheets to store the differences.
3.
Calculate the differences with formulas that subtract the values in the budgeted sheets from the
values in the actual sheets.
That solution sounded reasonable to CJ, but she had one question: “How do you perform calculations
across worksheets?”
CJ isn’t alone. A lot of experienced spreadsheet jockeys try to cram too much data into a single
worksheet because they don’t realize that “trans-sheet” calculations are possible. In this tutorial, I’ll
explain how to use a formula in one sheet to ref er to data in another sheet. (I’ll use Excel 2000 to capture
the screen shots, but the technique is identical for all versions of Excel.)
A sheet by any other name
Here’s the executive summary of the technique. To refer to a cell in another sheet within the same
workbook, use this format:
sheet_name!cell_reference
The exclamation point is required punctuation. Replace sheet_name with the name of the sheet and
cell_reference with a cell address.
Let’s look at a simple example. The default sheet names are Sheet1, Sheet2, and so on. Suppose you’re
working in Sheet2 and you want to refer to the entry in cell A2 in Sheet1. To do so, you’d use an
expression in the form +Sheet1!A2.
Now let’s see how this technique helped CJ accomplish her mission.
The budget example
To illustrate how trans -sheet math works, let’s look at CJ’s project. Figure A shows a simplified version of
CJ’s budget spreadsheet. (CJ’s actual sheet had nearly a hundred line items and dozens of
departments.)
Figure A
I’ll use this sample data to illustrate how to set up trans -sheet calculations.
To make a copy of the sheet named Q1Budgeted, just right-click the sheet tab and then choose Move Or
Copy from the context menu. When the Move Or Copy dialog appears, click the option (Move To End)
and activate the checkbox labeled Create A Copy, as shown in Figure B.
Figure B
Right -click a sheet tab and choose Move Or Copy to display this dialog.
When you click OK, Excel will create a copy of the current sheet and place the copy at the end of the list
of worksheets, as shown in Figure C. In CJ’s case, she used Q1Actual for the second sheet. (To rename
a sheet, just double-click the tab, type the new name, and press [Enter].)
When the actual numbers start coming in from the departments, all CJ has to do is go to the Q1Actual tab
and key in those values over the top of the budgeted numbers.
Figure C
After copying the worksheet, you can rename it by double-clicking the tab and typing a new name.
At this point, you create one more copy of the original worksheet and name it Q1Difference. Then, in cell
B2, enter the formula
+Q1Budget!B2 -Q1Actual!B2
The beautiful part about this formula is you only have to enter it once! Then copy it to all of the other cells
under the “department” columns. The sheet references stay the same, but Excel automatically adjusts the
cell references relatively so that each copy of the formula refers to the correct cells in the other two
sheets.
Figure D shows what our Q1Difference sheet looks like after we copied the formula. At this point, all the
values in the budgeted and actual sheets are identical, so they zeroed each other out in the difference
sheet. However, as soon as you start entering different values in the actual sheet, the trans-sheet
calculations will be updated automatically.
Figure D
We entered our trans -sheet formula one time and then copied it to the other cells in our difference sheet.
Another example: Year -to-date calculations
Here’s another popular application of trans-sheet math. Suppose you store data in sheets named for each
month, and you want to generate a year- to- date total. In your YTD sheet, you’d use a formula in the
following form:
=SUM(January!B2,February!B2,March!B2,April!B2,May!B2,June!B2,July!B2,
August!B2,September!B2,October!B2,November!B2,December!B2)
If you want to average the same set of values, you’d just use the AVERAGE function instead of SUM.
About moving sheets around
Here’s another tip that can help you manage multiple sheets. Suppose you want to rearrange the sheets
within your workbook. To do so, just click-and- drag the sheet tab. As Figure E shows, when you drag the
mouse, the cursor will change to an arrow with a blank page behind it. In addition, a black arrowhead
facing down will indicate the position where the sheet will “land” when you release the mouse.
Figure E
The circled area shows what the cursor looks like when you click- and- drag to move a sheet to a new position.
Why not do all the calculations in one sheet?
Some of you may wonder why CJ didn’t just put all of her budgeted and actual amounts in the same
sheet. Then she wouldn’t have to worry about performing trans -sheet math, right?
Theoretically, CJ could have crammed all of her data into one sheet. However, she wanted to make it
easy to print all three sets of values in separate reports. If she had stored the budgeted, actual, and
difference values in one sheet, she would have been forced to set up different print ranges or hide
columns when she wanted to print one of the three sets of values.
The trade-off, of course, is that she now has 12 sheets in the budget workbook: a budgeted, actual, and
difference sheet for each of the four quarters. But she thinks that’s easier to manage than hundreds of
columns in a single sheet.
About named ranges
Some of you may wonder whether you can refer to named ranges across sheets, and, of course, you can.
Here’s the skinny. Suppose you’ve assigned the range name myvalue to cell A2 in Sheet1. A range name
can be used only once in a workbook. So in any sheet, you can enter +myvalue, and Excel will return
whatever is in the cell you named myvalue.
It doesn’t hurt anything to include the sheet reference to access the data in a named range. For instance,
you could use +Sheet1!myvalue, and you’d get the same result as if you’d used +myvalue. However, with
named ranges, the sheet reference isn’t necessary.
Expand analysis options by importing external data into Excel
By Scott Lowe MCSE | Originally published by TechProGuild Nov. 4, 2002:
http://www.techrepublic.com/article_guest.jhtml?id=t01220021017low01.htm
Microsoft Excel is the data analysis tool of choice for many professionals. However, in order to be useful,
Excel needs to access data sets that may or may not be part of an existing Excel spreadsheet. To get
around this quagmire, Microsoft developed a number of ways to import external data into Excel. To
narrow it down a bit, I’ll discuss three of the most popular:
• Importing data from a Microsoft Access database
• Importing data from a comma-delimited text file
• Web queries
Office XP
I’ll be using Office XP for all of my examples in this article.
Importing data from Microsoft Access
I’ll use two methods to get Access data loaded into Excel for analysis. I’ll use the Northwind sample
database that comes with every Access installation so that it’ll be easier to replicate if you’re following
along at work. Specifically, I’ll use the data from the Products table in the Northwind database since it has
the most useful data to work with.
Method 1: Exporting the Access data
The first method of getting Access data into Excel involves exporting the Access data to an Excel
worksheet file directly and then simply opening that file in Excel. This method is definitely the most
straightforward way of importing foreign data. Thus, if possible, use this method to get the “cleanest” data
possible into Excel.
The first step in this process is to export the data out of Access and into an Excel workbook. To do this,
right-click the Products table and choose Export from the shortcut menu (Figure A).
Figure A
The next step is to choose what type of file you wish to export the Access data into. I’ve chosen to export
the data into an Excel 97-2002 workbook named Products-wb, as shown in Figure B. Completing the
process is as easy as clicking the Export button.
Figure B
Finally, to make sure that the export was successful, open up the workbook in Excel and check to see
that the data is there. In Figure C, you can see that I now have a Microsoft Excel worksheet that contains
that same data as the Access Northwind database Products table.
Figure C
Method 2: Directly accessing the data
The second way to get data from an Access database is similar to a method you can use to get data from
other database systems including Oracle, Microsoft SQL Server, and PostgreSQL. It involves creating an
ODBC (Open DataBase Connectivity) connection to the Access .mdb file and allowing Excel to access
the data directly rather than having to export it from Access first. To use this method, follow these steps
for a Windows XP system:
1. Click Start | Control Panel | Administrative Tools | Data Sources (ODBC).
2. Click on the File DSN tab.
3. Click Add.
4. Choose Microsoft Access Driver (*.mdb) from the list (Figure D).
Figure D
5.
6.
7.
8.
9.
Give the data source a name of Access-Products.
Click Next.
Click Finish.
In the database portion of the window, click the Select button.
Navigate to the directory containing the Northwind.mdb file and select it (Figure E).
Figure E
10. Click OK in the ODBC setup box to complete it (Figure F).
11. Click OK in the data source administrator window to complete the process.
Figure F
This process creates a file data source that Excel can use to directly make use of the Access table
(Figure G).
Figure G
Next, in a blank worksheet from Excel, choose Data | Import External Data | Import Data. Double-clicking
the Access-Products.dsn entry brings up a list of tables and views from the Northwind database, including
the products table (Figure H).
Figure H
Clicking OK brings up a dialog box in which you indicate where you’d like the data to be imported to. You
can import it into the current spreadsheet or into a new one (Figure I). I’ll import it into the current sheet
and click OK.
Figure I
Now all columns from the table are imported, as shown in Figure J. Notice also that there is a new
toolbar called External Data. You use this toolbar to manage the imported data. It includes an option to
refresh the data, which is particularly useful in situations where the source data may change frequently.
Figure J
That’s all there is to importing data from an Access database. If you want to import data from other
sources, you’ll need to create the appropriate DSNs in the ODBC Data Sources control panel as a first
step.
Importing data from a text file
Unfortunately, the data that you need to work with won’t always be packaged up in a nice database table
for you to use. More often than not, you’ll need to use data in the form of a text file. These file types are
sometimes referred to as flat files, comma-delimited files, or tab-delimited files. They’re created in a
number of ways; for example, some applications only export data to text files. When someone talks about
a comma- or tab-delimited file, they mean a data file in which the fields are separated by a certain
character, such as a comma or tab—hence the name. For this portion of the article, I’ve exported the
contents of the Northwind Products table to a comma-delimited text file.
Getting this data into Excel
Since spreadsheets are commonly used for data analysis, Excel is more than capable of importing almost
any kind of delimited file. To begin the process, choose File | Open, change the Files Of Type selection to
Text as shown in Figure K, navigate to the directory that contains the delimited file you wish to import,
and choose the file from the list.
Figure K
Once you choose the file that you wish to import, Excel will start the Text Import Wizard (Figure L ). On
this screen, you need to tell Excel what the format of the original data is—delimited or fixed width. If you
don’t know, look at the preview section below to determine it. A delimited file will have the fields
separated by commas, while a fixed-width file will have spaces separating the fields. This step also asks
for the row at which to begin the import, as well as the origin of the file. The file origin defaults to Windows
(ANSI), which is fine for this example. To continue to step 2, click Next.
Figure L
Figure M shows you step 2 of the w izard with the default options selected. By default, Excel assumes
that a tab character is separating the fields.
Figure M
In this example, the delimiting character is a comma instead of a tab character. To make the change,
select the Comma option and deselect the Tab option. The Treat Consecutive Delimiters As One option
allows you to consolidate multiple delimiters into one in the event that you have more than one between
fields. In this example, I don’t need to use this option. The final option, Text Qualifier, tells Excel where
text fields begin and end. If you look at the raw data in Figure M, you’ll notice that the text fields are
surrounded by quotes. If a delimiter character is inside a text field, it won’t be used as a delimiter but will
remain a part of the text field instead.
After changing the delimiter, step 2 looks like Figure N. Notice that the data preview section now shows
the data neatly lined up in columns and that the quotes are gone. Click Next to move on to step 3.
Figure N
The third and final step of the Text Import Wizard allows you to further “massage” the data into a useable
format (Figure O). By default, Excel imports every column in a “general” format. This means that Excel
converts numeric values to numeric fields, dates to dates, and all remaining types to text fields. This
default allows you to perform calculations properly.
Figure O
However, there might be times when you want to override the defaults. For example, suppose that a field
of numbers is supposed to be treated as text rather than as a number. In that case, you just click the
column heading in the preview pane and change the column data format to text. Clicking on Advanced
lets you change the way Excel recognizes numbers. This is useful if you receive a text file from a region
that handles numbers differently from yours. For example, if you receive a file in which a comma is used
as the decimal separator, you can make that change on the Advanced tab so that Excel knows that a
column contains numbers rather than text. When finished with the screen, click the Finish button.
This is the method you’ll most often use to import data into Excel, so it’s important to know how to handle
the various options. When you’re finished, your new spreadsheet should contain the data you need
(Figure P).
Figure P
Using a Web query
The final method of importing data into Excel involves using the Web to get data into an Excel workbook.
For example, suppose a user has a financial application in Excel that needs to know current exchange
rates for various exchanges. This rate conversion Web site has exactly the information the user needs,
and it’s updated on a daily basis, which is perfect for the job.
How does the user get this data into Excel to use the figures in calculations? To begin, start a new
workbook and choose Data | Import External Data | New Web Query, browse to the address in question,
and click Go (Figure Q).
Figure Q
You’ll see colored arrows on the Web page that you selected, each one pointing to a table embedded in
the Web page. Click on the yellow arrow that corresponds to the table that you wish to import. It will
change to a check mark indicating that this table is selected (Figure R).
Figure R
When you’re done, click the Import button. You’ll then be asked where you want to put the data—either in
the current book or in a new one. For this example, I’ll use the current workbook (Figure S ).
Figure S
Notice on this screen that the Properties button is enabled. Clicking this button brings up a number of
options relating to how this external data will be handled (Figure T).
Figure T
These options mainly control how the data will refresh; for example, the interval, how to handle new data
or deleted data, and cell formatting. The beauty of this is that you can change these options based your
needs and easily include dynamic data in your spreadsheet calculations— data that is updated throughout
the day.
Click OK on the import data screen to complete the Web query process. Figure U shows what this data
looks like.
Figure U
Save that query for other uses
One final piece of advice would be to save the query for use in other spreadsheets. You can do so from
the Edit Web Query or New Web Query windows (Data | Import External Data | New/Edit Web Query) by
clicking the save query button at the right. This saves the query with an .iqy extension. To show what one
looks like, I’ve included the Web query file from the preceding example:
WEB
1
http://www.uta.fi/~ktmatu/rate -crossrates.html
Selection=1
Formatting=None
PreFormattedTextToColumns=True
ConsecutiveDelimitersAsOne=True
SingleBlockTextImport=False
DisableDateRecognition=False
DisableRedirections=False
Teach Excel users to calculate elapsed time
By Jeff Davis | Originally published on TechRepublic Jan. 29, 2003:
http://www.techrepublic.com/article.jhtml?id=r00320030129jed01.htm
A TechRepublic member we'll cal l Zee wrote asking for help with date math. Zee, who works for a small
correctional institute, had an Excel spreadsheet with the following information:
•
Date of entry
•
Date of scheduled departure
Using that data, Zee wanted to calculate two new columns, "length of stay in years, months, and days,"
and "percent of total stay."
Fortunately, Excel offers a built- in function, DATEDIF, which makes it easy to calculate elapsed calendar
time. I sent Zee a sample solution, and she wrote back that it was exactly what she had in mind.
In this brief date-math tutorial, I'll explain how I generated the output Zee requested. The screen shots
were captured using Excel 2000. However, the process is identical in Excel 97, 2000, and 2002.
The easy part: Age in days
Zee's need is similar to that of business spreadsheet users who need to calculate the age in days of
unpaid invoices. Zee's date of entry is like the invoice date. Suppose the entry date or invoice date is
stored in cell A2, and you want to display in cell B2 the number of days that have elapsed between that
date and the current date. To do so, you'd enter the following code in cell B2:
=NOW()-A2
Then, Excel would calculate the age in days by subtracting the date value entered in cell A2 from NOW(),
which returns the current system date. Sort your unpaid invoices in descending order by that age in days
column, and you have an aged receivables report.
Zee's needs: "Length of stay so far"
The problem for Zee is that calculating the number of elapsed days isn't enough. Zee wants to express
that interval in the format X years, Y months, Z days.
So how do you convert an integer like 800 days into the appropriate number of years, months, and days?
To get such a result in the early spreadsheet days, you had to parse out the month, day, and year
components of the beginning and ending dates, and then jump through several If -test hoops to display
correct results.
Now there's the DATEDIF date difference function that takes this form:
=DATEDIF(begin_date,end_date,calendar_ u nit_option)
The begin_date and end_date parameters must be expressions that return dates or references to cells
containing dates. It's the number of options for the calendar_unit_option parameter that makes some
Excel users shy away from trying the funct ion. Let's look at the functions behind Zee's solution, shown in
Figure A.
Figure A
We used the DATEDIF function to generate the results of this date math.
Listing A shows what the formula in Figure A's C2 looks like.
Listing A
Cell C2 concatenates several DATEDIF functions
=CONCATENATE(DATEDIF(A2,B2,"Y"),IF(DATEDIF(A2,B2,"Y")=1," year, "," years, "),
DATEDIF(A2,B2,"YM"),IF(DATEDIF(A2,B2,"YM")=1," month, "," months, "),
DATEDIF(A2,B2,"MD"),IF(DATEDIF(A2,B2,"MD")=1, " day"," days"))
This formula concatenates (combines) into a single string the results of several functions. The DATEDIF
functions provide the numbers, and the IF tests provide the correct text labels. (Note the embedded
spaces following the year/years and month/months labels.)
Zee wants to show all three labels, even when the number of years, months, or days is zero. So, to make
sure the result is grammatically correct, we had to use the IF function to check each value. If the value
equals 1, the IF test returns one of the singular terms year, month, or day. In all other cases, where the
DATEDIF function returns 0 or any number greater than 1, the IF test returns the plurals.
Digging DATEDIF
Here's what to do if you want to calculate elapsed time in years, months, and days, but you don't need
text labels like Zee's. Assuming the begin and end dates are in A2 and B2, just enter the three core
function calls in separate columns. Here's how the expressions work:
•
Years. In the expression DATEDIF(A2,B2,"Y"), the "Y" parameter tells the function to return the
number of whole years between the two dates.
•
Months. The expression DATEDIF(A2,B2,"YM") returns the number of months between the two
dates, without regard to the years.
•
Days. Finally, the expression DATEDIF(A2,B2,"MD") returns the number of days in the interval
without regard to month and year.
Table A shows a short summary of all the unit -of -measure options available when you use DATEDIF.
Table A
OPTION RETURNS
"Y"
Full years between dates
"M"
Full months between dates
"D"
"YM"
Days between dates
Months between dates, ignoring year
"MD"
Days between dates, ignoring month and year
"YD"
Days between dates, ignoring year
Units of measure by DATEDIF options
Zee's length of stay so far
The other thing Zee wanted to determine was what percentage of each person's stay had elapsed. In
other words, she wanted to know the result of this calculation:
(Number of Days Stayed So Far) divided by (Total Number of Days in Planned
Stay)
Figure B shows the results of sample calculations. Since this tutorial is primarily about the DATEDIF
function, we used the expression
=DATEDIF(A2,C2,"D")/DATEDIF(A2,B2,"D")
In this formula, DATEDIF(A2,C2)"D") returns the number of days between the entry date and our given
date. The expression DATEDIF(A2,B2,"D") yields the number of days between entry date and expected
departure date.
Of course, in this case, you could have achieved Zee's results without the DATEDIF function. Since
subtracting two dates also yields the number of days between, the formula =(C2-A2)/(B2-A2) would result
in the same percentage.
Figure B
The DATEDIF function makes it easy to calculate percentage of time elapsed.
Show users how Conditional Formatting can dynamically update their Excel
spreadsheets
By John C. Iosub | Originally published on TechProGuild Sept. 26, 2002
http://www.techrepublic.com/article_guest.jhtml?id=t01220021010ICI01.htm
With the Conditional Formatting feature, Microsoft Excel allows users to format automatically the contents
of a cell based on a formula or set of formulas. This feature is very useful for highlighting certain areas of
the worksheet based on cell contents that may dy namically change. For users who routinely format data
sets, Conditional Formatting could boost their productivity tremendously. I’ll describe the Conditional
Formatting feature so you can show users how to change the look of their data on the fly.
Conditional Formatting in a nutshell
Here’s a quick way to understand how this feature works. Select a blank cell in a worksheet. Go to Format |
Conditional Formatting. Click on the first empty dialog box and enter any number. Next, click inside the last empty
dialog box and enter a number higher than your first entry. Click the Format button. Make the font style bold and the
color red. Click OK to accept this formula. Type in the cell numbers inside and outside the range you selected to see
how the cell format changes.
Applying Conditional Formatting to a column of values
Applying Conditional Formatting to one cell is easy, but how do you apply it to a whole table of values that
have multiple conditions? Let’s consider the table in Figure A.
Figure A
Our goal is to highlight the values in the Days Past Due column. We want to use bold, green formatting
for invoices between 30 and 90 days old. We want to use bold, blue, single -underline formatting for
invoices between 90 and 120 days old. The last condition is to have bold, red, double-underlined cells for
invoices older than 120 days.
To apply Conditional Formatting, select the first cell in the range. Add the first condition just as in the
“Conditional Formatting in a nutshell” example above. Use values of 30 and 89, and in the Format
section, choose bold and green. For this table example, you’ll need to add more conditions to complete
the formula. So, to add another condition, you would simply click on the Add button and use 90 and 119
as your values. Click Format and change the font style to bold, the underline to single, and the color to
blue. Click Add again to add the third condition to your formula. Change the Condition field to Greater
Than and use 120 as the value. Don’t forget to change the formatting to bold, red, and double underline.
Selecting OK will accept the formula and apply it to the current cell.
Using Format Painter, copy the formatting by selecting the cell with the conditional formatting and clicking
the Format Painter icon. Next, select the remaining cells in the Days Past Due column. Everything should
look similar to the table in Figure B.
Figure B
To delete a condition, first select the range of cells. Go to Format | Conditional Formatting and use the
Delete button.
Limitations of the Conditional Formatting feature
You probably noticed that you’re limited to three conditions when you use this feature. However, there is
actually a fourth condition to consider when no conditions match. In this case, you can choose the
formatting of the cell manually by selecting Format | Cells. In Figure B, an entire range of cells was
selected and manually changed to white. Values less than 30 will “disappear,” while the other values are
visible based on one of the three conditions.
Also, it’s possible to have formulas that would be true in multiple conditions. In this situation, the first true
condition wins. Keep in mind that in cases where more than one condition is true, the order of the
formulas is important.
Tip
Another limitation of the Conditional Formatting feature is that fonts cannot be changed. Besides style, underlining,
and color, you can change only background color and borders.
Advanced Conditional Formatting
So far, we’ve used the conditions based on “cell value is…” combined with options such as equal, greater
than, or less than. For more advanced Conditional Formatting techniques, there is a Formula Is option in
the first drop-down list of the dialog box.
We’ll further format the table from our prior example, so that all rows will present similar behavior with the
Days Past Due column. This is where understanding the Formula Is option becomes critical. We can use
this option to format a cell based on values contained in fixed or adjacent cells.
In our example, cell D2 contains the first value in the range. We’ll start with cell C2, and then we’ll copy
the formatting to the rest of the cells in the range. The first formula is =AND($D2>=120) with red, bold,
double-underline formatting. The second formula is =AND($D2>=90,$D2<120) with bold, blue, singleunderline formatting. The third formula is =AND($D2>=30,$D2<90) with bold, green formatting. The dollar
sign in $D2 was used to preserve the column reference, because we’ll copy the formula to the left to other
cells on the same row.
Tip
D2 means relative column + relative row reference. $D2 means absolute column + relative row reference. $D$2
means absolute column + absolute row reference. For example, if we copy the formula =AND($D2>=120) from C2 to
B2, the formula stays the same because of the absolute column reference. If we copy the formula down to C3, the
formula becomes =AND($D3>=120) because the row reference is relative.
Once the formulas are in place, we’ll use Format Painter again to copy the conditional formatting to the
rest of the table. There is one problem, though, because along with the conditional formatting, all other
formats (such as date or currency) are also applied. You can overcome this issue by selecting each
column and applying the correct number format. To do so, select the Invoice Number column, right-click
on the selection, and choose Format Cells from the menu. In the Number tab, select the Text category
and choose OK. Repeat the sequence with the Invoice Amount, but this ti me change it to currency. Do
the same with the Due Date column, only change its number format to the appropriate date style. The
final look should be similar to the table in Figure C.
Figure C
When values change, the formatting will always respect the imposed conditions automatically without the
need for user interaction or manual formatting.
Tip
In our example, we used constant values such as 30, 90, and 120 days. But such fixed values can be placed in cells
elsewhere in the worksheet and then referenced in the Conditional Formatting formulas. This allows for future
changes of such values without the requirement to change the Conditional Formatting formulas.
Get logical about Conditional Formatting
You may want to experiment by using more logical Excel functions with Conditional Formatting. These
logical functions can be represented as:
•
AND returns true when ALL arguments are true. The AND function can have up to 30 arguments.
•
OR also has 30 arguments and will return true when any of the arguments is true.
•
IF has exactly three arguments. The syntax is =IF(test, value_if_true, value_if_false).
These logical functions can also be nested in complex structures that allow for more advanced conditional
formatting.
Auditing error messages in Excel
By Jeff Davis | Originally published on TechRepublic Sept. 3, 2002:
http://www.techrepublic.com/article.jhtml?id=r00320020903jed02.htm
If you support Excel users, chances are you've received calls about error messages that mysteriously
appear in cells that previously displayed values. To help those users eliminate error messages, try using
Excel's Auditing tools. They'll save time for you and your users by providing visual cues to the possible
sources of the error condition.
Select the cell; use the tool
You don't have to wait for an error condition to use the Auditing tools. They are great tools for teaching
Excel users how formulas work. In any worksheet, click on a cell and go to Tools | Auditing to display the
menu shown in Figure A. From there, you can use the Trace Precedents and Trace Dependents tools to
determine whether the current cell feeds information to or depends on information from any number of
other cells.
Of special interest to help desk analysts and technical trainers is the Trace Error tool, which only works
when the active cell contains an error value.
Figure A
The Auditing tools provide invaluable information for troubleshooting worksheets.
Tracing the error
To illustrate how the Trace Error tool works, consider the sample worksheet shown in Figure B. If you're
familiar with the VLOOKUP func tion, you probably know at a glance the reason for the #N/A error: The
formula in cell B14 depends on the entry in cell A14 to provide a value that is greater than or equal to
1,021.
In this sample formula, the #N/A error will result any time A14 is empty, contains a string, or contains a
value less than 1,021. Enter in A14 any number 1,021 or greater, and the formula will look up and return
a name from the second column.
Figure B
I used the Trace Error tool to pinpoint the reason this formula is returning an error message.
To use the Auditing tools during a help desk call, have the user click on the cell that contains the error
message, and then go to Tools | Auditing | Trace Error. Figure C shows what my sample worksheet looks
like after Excel audited the error message. The lines can help your end user see exactly where
information needs to be added or changed.
Let's start with the blue line that starts in cell A14 and points to cell B14. Blue lines point from cells that
provide information to cells that depend on that information. So that line visually tells us that the formula
in B14 depends in some part on the entry in A14.
Figure C
The Trace Error tool highlights the path to the cells that might be causing the error.
Now let's talk about the blue line that starts in A2 and points to cell B14. Notice what's special about cell
A2: It's the top-left cell in a range that's been set off by a blue border, which is the lookup range
referenced by the formula in B14. In this context, the blue border and the line from A2 pointing to B14
indicate that B14 depends in some part on the entries in all of the entries in A2:B11.
The red arrows
From time to time, Excel will use a red arrow instead of a blue one to point the way from a precedent cell
to a dependent cell. When that happens, you know you have at least one more error condition to deal
with. The red arrow means that the cell feeding the current cell contains an error.
Adventures in auditing
The Trace Error tool provides useful information for troubleshooting error messages. You'll also want to
experiment with the Trace Precedents, Trace Dependents, and Circle Invalid Data options.
When you finish troubleshooting, you erase the lines by going to Tools | Auditing | Remove All Arrows. If
you have a lot of error messages to work on, you may want to go ahead and display the Auditing toolbar
for easy access to the auditing tools, especially the eraser.
Don't be surprised if you're editing the worksheet and the arrows suddenly disappear. Excel will erase the
tracer arrows when you change the formula to which the arrows point, insert or delete columns or rows, or
delete or move cells. Just go to Tools | Auditing again to display the arrows based on the updated
information.
Save multiple print ranges in Excel
By Jeff Davis | Originally published on TechRepublic July 16, 2002:
http://www.techrepublic.com/article.jhtml?id=r00320020716jed02.htm
When you maintain Excel workbooks with dozens or even hundreds of columns of data, you probably
print those records one section at a time. Typically, you select the range you want to print, and then go to
File | Print Area | Set Print Area. Repeating those steps each time you want to print a different range is a
tedious process.
This week, I’d like to show you the easy way to save multiple print settings as part of your workbook. With
this approach, you can change the print range and other print settings with just a couple of mouse clicks.
Save the settings in a named custom view
The secret to saving all of your custom print settings is to create a custom view. We’ll use the sample
worksheet shown in Figure A to illustrate how this works.
Figure A
We’ll use this sample worksheet to illustrate how saving different print settings in custom views can save you time.
Let’s assume that for one audience, you want to print the first two columns in this sheet. For another
audience, you want to print all four columns. To begin, select the range of cells you want to print —in this
case the first two columns—and go to File | Print Area | Set Print Area.
Next, go to File | Page Setup and make sure the header, footer, page margins, and other print settings
are the way you want them. Then, go to View | Custom Views. When the Custom Views dialog appears,
click the Add button, and type a meaningful name for your view in the Name field.
Figure B shows what the Add View dialog looked like when I created the custom view Print2. In this case,
the name I entered means “print two columns from our worksheet."
Figure B
The Add View dialog lets you designate a name for your custom view.
After you enter a name for your custom view, click OK. Figure C shows the print preview screen for this
particular print job.
Figure C
Here’s what my first custom view looks like in preview mode.
To create a custom view called Print4 that will print all four columns in our sheet, select all four columns of
data, and then go to File | Print Area | Set Print Area. Make any changes to your header, footer, or
margins as required to make this new print range fit on the page properly. (In my sample sheet, I changed
the custom header.)
Finally, go to View | Custom Views and click Add. Then type a name for your field— I used the name
Print4—in the Name field and click OK. Figure D shows w hat my print preview looks like with the new
settings in place.
Figure D
Here’s what my Print4 custom view looks like in print preview mode.
Then, save your worksheet. The next time you need to print either view of your data, just go to View |
Custom Views. Your named views will appear in the Custom Views list, as shown in Figure E. To activate
either view, simply select it, and then click the Show button.
Figure E
After saving your print settings in custom views, you can switch print settings by selecting a view and clicking Show.
Print settings are only the beginning
Comment: I removed a paragraph mark
from the beginning of the page and
inserted a page break on the previous
page. Figure E's header, image and
caption now appear on the same page. At
least they do for me.
In my example, I used Excel’s Custom Views to save time when I need to print several different ranges
out of the same sheet. As you’ve probably guessed, Ex cel’s Custom Views provide many other ways to
save you time and trouble.
In addition to print ranges and options, you can also save views of attributes such as column widths,
window size and position, splits or frozen panes, and other settings that affect the way your data appears.
Just set up your sheet the way you want it to look, and then save those settings under a custom view.
VB script lets you print the file path in Excel 2000 worksheet footers
By Gregory Harris | Originally published on TechRepublic June 21, 2002:
http://www.techrepublic.com/article.jhtml?id=r00320020621hrs01.htm
One of the companies I consult for stores its documents on a LAN and requires that printed copies
display a path in the document footer. It’s easy to set this up in a Word document via the Header And
Footer toolbar. But in Excel 95, 97, and 2000, the header and footer options are much more rudimentary;
there isn't an obvious way to insert the document path.
A common workaround is to type the document’s path into the footer manually. While a sensible solution,
this approach is more labor -intensive; typing a single document path is no big deal, but in a company that
maintains hundreds or thousands of spreadsheets, the effort can really add up. Also, the typed path is
static; if the spreadsheet is moved or saved to a new location, the path doesn’t change. And that fact
might not get noticed until the document is printed, wasting both time and paper.
However, you can use a simple, one-line Visual Basic script in Excel 2000 to allow printing of a selfupdating file path in the footer of your worksheets. The script even gives you a number of positioning
options.
Check your headers and footers
A common laborsaving approach is to reuse existing document files as templates for new work. Unfortunately, since
several view modes in both Word and Excel don’t display the header and footer, it’s easy to overlook these elements
until the document is printed. Headers and footers that do not use automatically updating fields can contain incorrect
filenames, page counts, and other information. Taking a few moments to check the information in a document’s
header and footer can prevent waste and confusion.
Basic header and footer technique
Most people are familiar with how Word handles file paths in headers and footers; it's quite different from
Excel. In Word, you click View | Header And Footer to invoke the Header And Footer toolbar. If you’re
using Print Layout view, you can also double-click on the footer area. To add a file path to the footer, you
simply choose Filename And Path from the Insert AutoText drop-down menu, as shown in Figure A.
Figure A
Word lets you insert a filename and path into your footer via a simple drop - down menu.
Works in Excel 95 and 97, too
I’ve used Excel 2000 in my examples. However, the script I explain below works in Excel 95 and 97 as well.
Excel 2000 handles things a little differently. Clicking View | Header And Footer in Excel invokes the Page
Setup dialog box with the Header/Footer tab activated, as shown in Figure B. From this dialog box, you
can select common footer entry options from the list (i.e., page number, worksheet name) from the Footer
drop-down menu, or you can click the Custom Footer button to create your own entry.
Figure B
Excel lets you choose from preset footer entries or create a custom footer, but its options are limited.
In the Footer dialog box, shown in Figure C, you can type text into the left, right, or center sections,
choose an entry from one of the seven buttons in the middle of the dialog box (where the entry goes
depends on what section your cursor occupies), or combine one of these entries with text you enter. The
seven selections are represented as icons. The options are (from left to right in the image):
•
Font
•
Page number
•
Total number of pages
•
Date
•
Time
•
Filename
•
Worksheet name
Figure C
Excel 2000 doesn’t provide a file path footer option.
As you can see, there is no option for entering a file path. To do this, you can use a simple Visual Basic
script.
No need for the script in Excel 2002
Excel 2002 does offer a file path option; you can click the button or type the code &[Path] into one of the sections of
the Custom Footer dialog box.
The script
The script is easy to use, even if you don’t have much Visual Basic experience. Simply choose Tools |
Macros | Visual Basic Editor or press [Alt][F11]. With the Visual Basic Editor open, choose Insert |
Module. In the resulting window, type the following code:
Sub FooterPath()
ActiveSheet.PageSetup.LeftFooter = ActiveWorkbook.FullName
End Sub
Close the Visual Basic Editor and return to the spreadsheet. Be sure to save the workbook before running
the macro. Next, click Tools | Macro | Macros, make sure the FooterPath macro is selected, and then
click Run.
That’s it! The spreadsheet will then have the full path in the footer. To confirm, click the Print Preview
button on the Standard toolbar. You’ll see the path at the bottom, as shown in Figure D. If you’re
comfortable with Visual Basic, you can alter the script to place the path in the right-hand corner, center, or
header.
Figure D
The macro places the path at the bottom of your worksheet.
If you move or rename the worksheet, you’ll need to run the macro again. But you can save this macro as
part of your Normal template, so it’s always available. Also, you can create a macro button or key
combination to make updates a pinch.
Finding and flagging subsets of Excel records
By Jeff Davis | Originally published on TechRepublic Jan. 22, 2002:
http://www.techrepublic.com/article.jhtml?id=r 00320020122jed01.htm
Recently, a consulting client called to ask the following Excel question: How can I find all the records that
contain a particular word in a certain column?
My first reaction was to recommend Excel’s AutoFilter feature. Go to Data | Filter, and then click on the
dropdown arrow for the appropriate column and choose the appropriate value—or in this case, the
appropriate word. Excel will filter out all records except those that contain that word.
That solution would have worked except for one crucial detail: The column in question contained long text
labels, not single-word entries. The client wanted to locate all the records where the key word appeared
anywhere within those text labels. Furthermore, the key word might appear with an in itial capital or in all
lowercase letters.
Fortunately, Excel provides all the tools needed to ferret out the records that contain the key word. Here’s
the solution I recommended.
Find, flag, and sort
We’ll use the Find function simply to “flag” the records that contain a particular key word. Once those
records are identified, the client can copy those rows out to another worksheet.
The solution I proposed was to use the Find function, which takes the form
=Find(string_to_find,source)
In this case, the client wanted to find all the records in which the word “sensitive” appears in the label. If
the word “sensitive” had been entered in all lowercase letters, we could have used the formula
=Find(“sensitive”,A2), assuming the source labels start in cell A2.
Another wrinkle was the fact that, in some of those labels, “sensitive” was the first word in the label and
was initial capped. To address that problem, we simply wrapped the Lower function around the cell
reference. (The Lower function converts a given s tring to all lowercase letters.) So our formula took the
form:
=Find("sensitive",Lower(A2))
Figure A shows what our sample sheet looked like after we copied our formula. For labels that do contain
our keyword, the Find function returns an integer corresponding to the word’s position within the string.
Notice that, for labels that do not contain the key word “sensitive,” the Find function returns the #VALUE!
error message.
Figure A
If the Find function locates an occurrence of the specified string, it returns an integer; otherwise, it returns an error message.
We could modify our formula so that it returns a null string instead of the error message. However, in this
case, we count on the error message to identify records that we want to exclude from our search. So, we
simply sort our records primarily by the Is Found column, and, as Figure B shows, all of the records we
want—the ones with integers in the Is Found column—get sorted to the top of the list.
Figure B
By sorting our records by the Is Found column, all of the rows that contain our key word move to the top of the list.
Advanced options
If your Excel users are like my client, they’ll learn to love using the Find function to flag records that
contain a particular string in a given column. In future tips, we’ll learn some other techniques for finding
subsets of Excel records, including how to set up criteria ranges for use with Excel’s Advanced Filter tool.
Create custom Excel add-ins to save your users time and effort
By Todd Parker | Originally published on TechRepublic Oct. 10, 2002:
http://www.techrepublic.com/article.jhtml?id=r00320021010pkr01.htm
I know what you’re thinking, “What good are add- ins, and why would I want them?” If you already know
Visual Basic for Applications (VBA), creating a custom Excel add-in will be a cinch. If you’re just learning
VBA, you’ll find that add-ins are a great way to expand your knowledge and put some power behind
Excel.
Although the add-ins that come with Excel are quite useful, you can also create your own custom add-ins
that can be helpful to your Excel users. The add-in sample referred to in this article will create a new
toolbar with two new buttons on it. The new buttons will enable you to make a single click when you want
to perform the commands Copy | Paste | Special Values (CPSV) or Paste | Special Values (PSV). This
comes in handy when you have cells containing formulas and you want to remove that formula and just
show the resulting value.
Using Excel's add-ins
Add-ins are special Excel workbooks containing Visual Basic modules that can extend the capabilities of Excel. Excel
comes with some add-ins already installed, and you may have looked at the Add-Ins menu in Excel. To use them,
you simply need to turn them on. Each add-in gives you different options and capabilities. For example, if you open
the Add-Ins screen (Tools | Add-Ins), you might find the first one listed as Access Links, assuming you have Microsoft
Access installed. By selecting the check box for that add-in, you'll have some new options under your Data menu.
CPSV copies and pastes the value or values directly into the same cell(s), whereas PSV requires that you
copy your cell(s) first, choose a destination, and then click the PSV button, thus giving you the values in
the new location. Normally, to paste the values of formulas, you would need to copy your cell(s), choose
Edit | PasteSpecial, select values, and then click OK. So these new buttons can save your Excel users
from having to click as much.
Download our handy Copy | Paste | Special Values Excel Add-In
You can download a copy of the Excel add-in described in this article from TechRepublic. The file contains both an
Excel workbook (SpecialButtons.xls) file and the add -in (SpecialButtons.xla) file. To increase download speed, we've
zipped these two files together. You'll need an unzip utility, such as WinZip, PKZIP, or WinAce, to expand the zipped
file. You will also need Microsoft Excel. Each of these files has also been included with this download to save you
time and effort.
Creating the add-in
To start the creation of your add-in, simply open a new Excel workbook. During the development stages,
save the workbook as an .xls file. However, when you've finished developing your VBA code module,
you'll save this workbook as an add-in (.xla), instead of a workbook (.xls) file. When you save your .xls file
as an .xla, the worksheets you have in the workbook become invisible and cannot be viewed. However,
it’s important to note that you could populate data on those sheets, and then even allow your add- in to
call upon the data from those sheets.
First, make sure you have your Visual Basic toolbar available. Right-click anywhere on your Excel toolbar
and choose Visual Basic. You should then have a new toolbar, which contains an icon for the Visual
Basic Editor. This is where you'll build your new functionality. To begin, you need to insert a module into
your project, so click Insert | Module within the Visual Basic Editor. Then, insert the two subroutines found
in Listing A.
Listing A
Sub CopyPasteSpecialValues()
On Error GoTo ErrExit
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ExitSub:
Exit Sub
ErrExit:
MsgBox Err.Number & " " & Err.Description, vbOKOnly, _
"Error in SpecialButtons Add-In"
Resume ExitSub
End Sub
Sub PasteSpecialValues()
On Error GoTo ErrExit
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ExitSub:
Exit Sub
ErrExit:
If Err.Number = 1004 Then
MsgBox "You cannot Paste, unless you've not copied something first.", vbOKOnly, "Ooops - You silly bird"
Else
MsgBox Err.Number & " " & Err.Description, vbOKOnly, _
"Error in SpecialButtons Add-In"
End If
Resume ExitSub
End Sub
These routines give you the Paste Special functionality behind the two buttons. I have included a special
error check in the PasteSpecialValues routine. This error check is important to this particular routine
because it requires that the cell(s) first be copied before it (they) can be used. You could modify this addin to disable the button until something is copied, which may be more effective for your users.
That’s all you'll need for your module. Next, double-click on this workbook, so you can insert your final
code within it. This subroutine will execute at the Open() event of the workbook, allowing you to add the
toolbar with the buttons, assuming it’s not already there. Then, insert the code from Listing B.
Listing B
Private Sub Workbook_Open()
Dim MyBar As CommandBar
'- - If the toolbar already exists, then exit sub.
For Each MyBar In Application.CommandBars
If MyBar.Name = "SpecialButtons" Then
Exit Sub
End If
Next
Set MyBar = Application.CommandBars.Add("SpecialButtons")
'- -Add the two buttons.
With Application
Set myControl = MyBar.Controls _
.Add(Type:=msoControlButton)
With myControl
'- -The following is the image on the button.
'- -Set this id to whichever image id you would like.
.FaceId = 9
.Caption = "&CPSV"
.OnAction = "CopyPasteSpecialValues"
End With
Set myControl2 = MyBar.Controls _
.Add(Type:=msoControlButton)
With myControl2
.FaceId = 10
.Caption = "&PSV"
.OnAction = "PasteSpecialValues"
End With
MyBar.Visible = True
End With
End Sub
The Type=msoControlButton creates your simple button; however, there are many options here. You can
create drop-down menu items, pop-ups, and much more. The FaceId property allows you to set the look
of the button but not the functionality. You can have a custom image placed on the button, which is an
entirely separate topic. For the purposes of this example, I have simply pointed to the image of another
button (Id 9 & 10) that isn't being used by any standard Excel features. The OnAction property points to
the subroutines you created previously in your module.
It’s always best to compile your application before you finish, so click Debug | CompileVBAProject. Then,
you can save your project as an .xla (add- in) file named SpecialButtons.xla.
Deploying the add-in to your users
To deploy this to your users, place your SpecialButtons.xla add - in in a special folder on your client’s
computer. You could place it in with all the other Excel add-ins, but this is located in different areas,
depending on the operating system on the client. It would be best to search for all .xla files first—
although, it doesn't really matter where on the hard disk the .xla file resides. I usually create my own
custom add-ins directory on each machine.
Once you've copied the file to your client, open Excel. Go to Tools | Add- Ins and click Browse. Locate
your new SpecialButtons.xla file and select it. Once you include this add- in, your new toolbar will appear
(see Figure A), centered in Excel.
Figure A
If the toolbar doesn't appear automatically, go to View | Toolbars and sel ect SpecialButtons. Drag-anddrop it with all the other toolbars, and it will lock into place. From then on, when you open Excel, the addin will be called upon and it will verify that the toolbar exists, and then create it, if needed.
For more informatio n from Microsoft on developing Excel add-ins, visit the Excel Add-ins page on MSDN.
Track business hours with Excel's WORKDAY function
By Gregory Harris | Originally published on TechRepublic Dec. 6, 2001:
http://www.techrepublic.com/article.jhtml?id=r00320011206hrs01.htm
As an IT support professional, there are many situations that might require you to accurately track time.
Perhaps your manager has asked you to estimate the cost of a software rollout. While Excel’s DATE
function makes it easy to find the difference between two dates, problems can arise if you only want to
calculate workdays. Fortunately, Excel offers a function to do the job. Excel’s WORKDAY function returns
the number of workdays after a start date, and even considers holidays. Here’s how to prepare the
spreadsheet:
Download this handy spreadsheet
Click here to download a fully functioning copy of the Excel spreadsheet Gregory Harris illustrates in this article from
TechRepublic. You will need a file unzip utility such as PKZIP or WinZip to extract the download file. You will also
need Microsoft Excel 2000 to view the spreadsheet. This spreadsheet has also been included with this download
under the filename workday_function1.xls to save you time and effort.
Starting out and adding on
Here's the situation. Our manager has just asked us to calculate the most cost-effective way to roll out a
new software package by a specific deadline. We've decided to create a spreadsheet that calculates the
per-hour cost of technicians with or without overtime and the impact of adding more workers to the job.
However, it soon becomes obvious that Excel's DATE function isn’t quite up to snuff for this task. While
we can quickly convert hours worked into days and then add the elapsed time to the starting date, the
result doesn't take weekends into account. Enter the WORKDAY function.
First, let’s set up the simpler elements of our spreadsheet. We want to track “Project A,” the rollout of a
new software package, for our department. Let’s start by entering some basic data.
We’re beginning the project on Dec. 1, 2001, and we need to have it completed by the end of the year.
The project will take a minimum of 160 hours to complete. Our assets include at least one technician, who
makes a standard wage of $50 an hour and $75 per hour of overtime. We also have to pay our consulting
firm a surcharge of $200 for each extra technician we use. (That won’t have any effect on today's
example, but it’ll change the numbers when it comes time to mull different scenarios in my upcoming
article on Excel's Scenario feature.) When we’d entered this information, our spreadsheet looked like the
one in Figure A.
Field CodeChanged
Field CodeChanged
Figure A
Begin with some basic information.
Next comes a vital preparatory step. To use the WORKDAY function, we have to activate Excel’s Analysis
ToolPak. To do so, choose Tools | Add-ins. In the resulting dialog box, select the Analysis ToolPak
option, as shown in Figure B. (If the component isn’t installed, Excel might ask you to provide the Office
CD-ROM.) Without this add- in activated, you can still enter the function, but you’ll get the #VALUE! or
#NAME! error message.
Figure B
Activate Excel’s Analysis ToolPak to access the WORKDAY function.
More bookkeeping
We’re almost ready to introduce the WORKDAY function, but first, let’s enter the simpler formulas. In cell
D14, add the formula
=D8*D9*D12
to calculate the regular wage cost; cell D15 contains the similar formula
=D8*D10*D13
to handle overtime. Cell D16 will total the regular and overtime hours using the formula
=D8*(D9+D10)
Rather than apply a lot of complicated IF logic, let’s just use some conditional formatting to warn us if the
total hours are different from our project duration. Select cell D16 and choose Conditional Formatting from
the Format menu. In the resulting dialog box, select Not Equal To from the second drop-down list and
type 160 in the third text box, as shown in Figure C .
Figure C
Conditional Formatting will warn you if the hours worked don't match.
After applying the condition, click the Format button and apply any conspicuous formatting. We chose a
red text color, but you can change the cell shading, apply a border, or establish any combination of
settings. When you click OK, you should see no change because you currently have a result of 160 total
hours in cell D16.
To determine the total labor cost, enter the formula
=(D8*(D9*D12))+(D8*(D10*D13))+(D11*(D8 -1))
into cell D6. This formula multiplies the number of workers by regular and overtime hours and adds the
$200 surcharge for each additional worker. Given the numbers already in the spreadsheet, Excel should
provide the expected figure of $8,000. So far, so good!
The function
Now it’s time for the WORKDAY function’s debut. Its syntax is
WORKDAY(start_date,days,holidays)
where start_date is the date you want to use as a basis for calculation, days is the number of elapsed
days, and holidays are any days you want to exclude from the count.
•
A negative figure for days provides the number of days prior to the start date.
•
You can enter days either as Excel serial date values or in the "MM/DD/YY" format, including
quotes.
•
Any of the function’s arguments can be a cell reference or calculation.
So let’s see how we’d use this formula to estimate the project’s completion date. In cell D5, we enter
=WORKDAY("12/01/01",(D9/8),{"12/24/01",37250})
Doing so establishes our start date of Dec. 1, divides the total hours by eight to provide the number of
elapsed days, and recognizes holidays on the 24th and 25th. Notice that we entered the holidays in array
format but combined literal and serial date formats. When we hit [Enter], the function returns a value of
01/01/02, as you can see in Figure D.
Figure D
The WORKDAY function takes both working days and holidays into account.
Uh oh! Given the holidays, there’s no way one person working regular hours can complete the task by the
31st.
Manage multiple possibilities with Excel scenarios
By Gregory Harris | Originally published on TechRepublic Dec. 21, 2001:
http://www.techrepublic.com/article.jhtml?id=r00320011221hrs01.htm
An Excel spreadsheet is a wonderful tool for “what if” analysis because you can change results
throughout the workbook by editing a single cell. A disadvantage to this process, however, is that it isn’t
always easy or convenient to restore the original values, especially when you’re changing multiple cells.
Fortunately, Excel offers the Scenario Manager, which allows you to substitute values in a number of cells
and save that condition under a unique name. By invoking a number of scenarios, you can easily
demonstrate to customers and managers the impact of different events or possibilities.
In my previous article, “Track business hours with Excel's WORKDAY function,” I introduced the
WORKDAY function by creating a spreadsheet that calculated the number of working days required to
complete a 160-hour project. Since the WORKDAY function accounts for holidays as well as weekends,
we discovered that one person couldn’t complete the software rollout before the December 31 deadline.
In this article, we’ll apply Excel’s Scenario Manager to the same spreadsheet to examine the impact of
various solutions.
Download this handy spreadsheet
Click here to download a fully functioning copy of the Excel spreadsheet Gregory Harris illustrates in this article. You
will need a file unzip utility such as PKZIP or WinZip to extract the download file. You will also need Microsoft Excel
2000 to view the spreadsheet. This spreadsheet has also been included in this download under the filename
scenarios1.xls to save you time and effort.
The original scenario
Let’s quickly recap the situation. We’re beginning a software rollout on Dec. 1, and we have to be finished
by the end of the year. The project will require at least 160 hours of work. We currently have one
technician available for the job, but we can hire more from a consulting firm for a $200-a-head surcharge.
Technicians make a standard $50 an hour ($75 overtime). These figures appear in the Scenarios.xls
worksheet shown in Figure A . For a review of the formulas and functions we used, refer to the previous
article.
Field CodeChanged
Field CodeChanged
Figure A
We’ll apply scenarios to finish this project by December 31.
We’ll assume that we can’t fudge the amount of time the project will take (we set up the spreadsheet with
some conditional formatting to warn us if the total hours don’t equal 160) or begin prior to Dec. 1 (actually
Dec. 3 since Dec. 1 is a Saturday). While only a one-hour adjustment can bring us back to Dec. 31, we’ll
also assume that finishing early is desirable, and there’s even extra money in the budget! Therefore, our
options are to bring in more contractors, allow overtime, or both.
Applying scenarios
Although you can use the Scenario Manager to apply a nigh-infinite number of combinations, we’ll restrict
the scenarios we examine to two: paying our sole contractor some overtime or hiring additional
contractors. Once we’ve created the scenarios, we’ll be able to compare our solutions. First, we’ll invoke
the Scenario Manager to save our current (and unacceptable) condition.
Choose Scenarios from the Tools menu. In the Scenario Manager dialog box, click Add. In the resulting
dialog box, type Original in the Scenario Name text box, as shown in Figure B. Click OK.
Figure B
Save your original condition as a scenario.
Even though this scenario will reflect the spreadsheet’s current values, we have to establish the range of
cells that will potentially change so w e can restore their values. In the Changing Cells text box, type
D8:D10 or use the Collapse Dialog button at the right side of the text box to manually select the cells that
hold the # Technicians, Regular Hours, and OT Hours values.
When you click OK, you’ll see the Scenario Values dialog box. Ensure the values for cells D8, D9, and
D10 are 1, 160, and 0, respectively, as shown in Figure C, and click OK.
Figure C
We start with one contractor and no overtime.
Single contractor overtime
Now let’s see what happens when we pay our current technician a bit of overtime to get the job done
faster. We’ll authorize 40 hours of overtime, leaving 120 standard hours. The Scenario Manager dialog
box should still be active; if not, choose Tools | Scenarios. In the Scenario Manager dialog box, click Add.
In the Add Scenario dialog box, call this scenario Single Contractor Overtime. (Be as descriptive as
possible so you can distinguish the scenarios later.)
When you click OK, you’ll again see the Scenario Values dialog box. This time, we’ll provide new values.
For cell D9, type 120 and enter 40 in the text box for cell D10; the value in D8 remains the same.
Click OK, ensure that the Single Contractor Overtime scenario is selected, and click Show. Excel reports
that we now finish on Dec. 21 with an additional $1,000 cost, as you can see in Figure D.
Figure D
When we authorize overtime, we finish ahead of our deadline.
We now have a solution, but is it the most cost-effective one? Here’s where the Scenario Manager really
shines: By letting you easily switch between different data sets, you can quickly determine the best
solution. In this case, since the Scenario Manager dialog box doesn’t obscure any of the changing cells (a
luxury you might not always enjoy), you can even click back and forth between scenarios and observe the
changes instantly.
Three contractors
In the Scenario Manager dialog box, click Add again. The Add Scenario dialog box appears. In the
Scenario Name text box, type Three Consultants. The Changing Cells (D8:D10) should already appear in
the proper text box; if not, enter that range. Click OK to invoke the Scenario Values dialog box.
Now let’s see what happens when we bring in two outside consultants (by charging $200 f or each
additional technician, we ensured that values would be different for various combinations). Enter 3 in the
text box for cell D8 and 0 in the text box for cell D10. This time, there’s a twist: Since 160 doesn’t divide
equally among 3, we’ll enter a formula, not a value, for cell D9. In cell D9’s text box, type =160/3. When
you click OK, you’ll see the message box shown in Figure E, informing you that Excel converted your
formula into a value.
Figure E
Your formula has been converted into a value.
Click OK to dismiss the message, and Excel returns you to the Scenario Manager dialog box. Sure
enough, when you select Three Contractors and click Show, Excel displays 53.3333333 in cell D9, as you
can see in Figure F. Nevertheless, the total hours are exactly 160; recall that we’d established conditional
formatting to highlight cell D16 if it contained any other value. This scenario gives us a completion date of
12/10 with a cost of $8,400.
Figure F
The Scenario Manager handles formulas as well as values.
Compare the possibilities
Now that we’ve created the scenarios, we can compare them to determine the best solution. Figure G
summarizes the results.
Figure G
As you can see, bringing in two more consultants gets us finished the earliest and at the least additional
cost. Excel’s Scenario Manager made this “what if” analysis a snap!
Use Excel check boxes to create a list -totaling spreadsheet
By Gregory Harris | Originally published on TechRepublic Nov. 20, 2001:
http://www.techrepublic.com/article.jhtml?id=r00320011119hrs01.htm
As my office’s resident Excel guru, I often discover handy tricks unknown to many casual Excel users. For
example, the Excel’s Scenario feature (select Tools | Scenarios) lets you save different values in the
same cells without retyping.
But sometimes you may have a list of values you want to total in varying combinations, such as a price
list. One way to accomplish this task would be to mark certain cells and then add the values in the
associated cells. Unfortunately, this solution is difficult, because:
•
Marking a cell requires clicking in a cell, typing a character, and then pressing [Enter].
•
Removing a mark involves selecting a cell and pressing [Delete].
•
Unless you set up input restrictions, the character used to mark the cell could vary, which might
affect conditional formulas.
Fortunately, Excel’s Forms toolbar offers a much more intuitive solution: check boxes. You can easily set
up a spreadsheet list that, when the associated check boxes are selected, totals the valu es of the
selected items. Here’s how to set up an intuitive checklist in Excel 2000.
Setting up the check boxes
We’ll demonstrate the technique with a spreadsheet you may download. The example spreadsheet lists
PC components in column A and their prices in column B. Simple functions show how much all the listed
components cost and their average prices, but the checklist you build totals the items checked in any
combination.
First, format column C to a width of 1.86 to hold the check boxes.
Download this handy spreadsheet
Click here to download a fully functioning copy of the Excel spreadsheet Gregory Harris illustrates in this article. You
will need a file unzip utility such as PKZIP or WinZip to extract the download file. You will also need Microsoft Excel
2000 to view the spreadsheet. This spreadsheet has also been included with this download under the filename
checkboxsample.xls to save you time and effort.
Field CodeChanged
Field CodeChanged
Invoke the Forms toolbar by navigating to View | Toolbars | Forms or by right-clicking a toolbar and
choosing Forms. Select the Check Box tool and then click the cell in column C next to the price of the first
component. If necessary, use your arrow keys to nudge the box so it sits squarely over the column (see
Figure A). (The check box doesn’t occupy the cell but rather sits on top of it like any Excel object; I will
discuss how to take advantage of this property in a moment.)
Figure A
By using the Excel Forms toolbar, you can place a check box over a spreadsheet cell.
Now you’ll need to format the check box. First, select the default check box text and delete it. Now, either
select the Control Properties button on the Forms toolbar or right-click your new check box and choose
Format Control. The Format Control dialog box appears. Enter the address of the cell beneath the check
box in the Cell link text box, as shown in Figure B, and click OK.
Figure B
Entering an address in the Cell link text box gives that cell a value of True when the check box is selected.
Unfortunately, this process can get a bit tedious, as you need to rep eat it for each item. However, you
can’t simply copy and paste one formatted check box because doing so selects all items when you check
any one box.
When you’re finished creating the check boxes, you can improve their appearance by dragging or
nudging them individually, or you can use a quick method to align them. Select the Arrow tool on the
Drawing toolbar. Shift-click each check box to select them. From the Drawing toolbar’s Draw menu, select
Align or Distribute and then choose Align Left, as shown in Figure C. (Don’t choose Align Center; since
the check boxes might be of different widths, doing so would skew the column.) Be sure to deselect the
Arrow tool when you’ve finished.
Figure C
You can use a quick method to align the check boxes.
Now, since the check boxes are currently deselected, the cells they’re over (and linked to) hold a value of
False. The value becomes True when the check box is selected and reverts to False when deselected.
You can take advantage of this fact to create some conditional formulas that’ll total the selected
components.
The formulas
As we mentioned, the SUM function in cell F4 adds the prices in column B. To keep them inconspicuous,
we’ll put the conditional formulas in column H. Our first item is in row 4, so in cell H4, enter:
=IF(C4=TRUE,B4,"")
Use Excel’s Fill feature to copy the formula to the other rows. Now, in cell F6, enter a simple SUM
function that adds the values in column H. That’s all there is to it!
Now when the user selects a check box, the value of the underlying cell becomes True. (By setting the
width of column C to 1.86, you prevent the text from appearing.) Excel displays the corresponding value
in column H and adds it to the total in cell F6 (see Figure D). If you want, you can format column H so the
values are invisible by making the text color white, as shown in the downloadable example.
Figure D
The spreadsheet now displays the total price of the selected items.
One nice thing about the check box technique is that it works even if the list is reordered. As you can see
in Figure E, we’ve sorted the list by price, but the spreadsheet still functions exactly as before. Of course,
if you add items to the list, you’ll need to add corresponding check boxes, and if you delete an item, be
sure to delete its check box!
Figure E
Sorting the table has no effect on the formulas.
Design timesaving Excel sheets with growth in mind
By Jeff Davis | Originally published on TechRepublic Oct. 30, 2001:
http://www.techrepublic.com/article.jhtml?id=r00320011030jed02.htm
Recently, a small business owner asked me to help design a computer -based solution to replace a paperand-computer-based process in his office. "And I'd like to keep the cost low," he said. (I hate it when
clients say that, but that's another story.)
I went on-site and met with the employees involved in the process that needed automating. I ended up
selling a solution that the client liked for two reasons : It came in under his stated budget, and it's designed
so that his employees can easily make enhancements in the future.
The not-so-handy manual process
The client manages information about unemployment claims for a variety of employers. In essence,
here's what happened under the old system:
1.
A claim was received in the office.
2.
The business analyst handwrote an employee identification number (EIN) on a form that
contained spaces for a dozen or so other pieces of information.
3.
The business analyst went to the computer room, opened an Excel sheet with 35,000 or so rows
of data, pressed [Ctrl]F, and searched for the EIN in question. (Not all employees know about
[Ctrl]F. Some of them drag the scroll button or press [PageDown] and manually navigate the
sorted list.)
4.
Assuming the EIN was found, the business analyst copied by hand information from the screen
onto the paper form.
5.
One of the fields that got copied was a six-letter location code. The business analyst fetched a
10-page, tattered printout, looked up the six-letter location code, and copied by hand contact
information onto the paper form.
6.
Finally, the business analyst got to do the work he or she was being paid to do —namely, to
analyze the claim, make some calls, take some notes, and make a recommendation.
The type -and-click solution and its effect on morale
The flow chart for the new process looks like this:
1.
A claim arrives in the office.
2.
The business analyst clicks on a shortcut to the Excel spreadsheet, now located on a network
drive.
3.
The analyst types the EIN, clicks a button, and the completed call sheet comes out of the printer
almost immediately.
The client initially measured the value of this new process for his business in the number of minutes per
day saved by each analyst. The formula is straightforward:
(No. of Analysts) * (No. of Claims Handled Per Day by each Analyst) * (No. of
Minutes it used to take to Fill Out the Form Manually).
Besides being a major time-saver, another benefit of the new process was the effect on the morale of the
business analysts. "You mean I don't have to look up the stuff for the form anymore?" they'd ask. When
completed forms started popping out of the printer, they were ecstatic.
The Excel design
The thing that befuddled the client was the fact that his people needed to pull data from two sources, a
spreadsheet and a printed list of locations, in order to start processing a claim. The solution I delivered
involved a single Excel notebook with three sheets, with their tabs labeled FromMainframe, OurLocations,
and OurForm.
•
In the FromMainframe sheet, we copied and pasted the 35,000 rows of raw data that the
business analysts previously searched manually. A new file is generated each month with the
data already sorted in the appropriate order. All the client has to do is delete the records in the
FromMainframe sheet and copy and paste the data from the new file.
•
In the OurLocations sheet, we entered all of the information contained on the 10 -page printout
that the business analysts had been using to look up location codes. In the past, when changes
were made to the names, telephone numbers, and addresses on these sheets, the only way to
disseminate the updated list was by photocopy and interoffice mail. Under the new system, the
business analysts don't even need a printed copy of the list— everything they need comes out on
the custom form. And if anyone wants to print a copy of the list of locations, it's readily available.
•
In the OurForm sheet, we re- created the look of the infamous original paper form. When the
business analysts open the worksheet, however, the only piece of information they need to enter
is the EIN. At that point, strategically placed VLOOKUPs return a set of fields from the
FromMainframe sheet that includes the six- character location code. Other VLOOKUP functions
use that six -character code to return information from the OurLocations worksheet.
After a quick review to make sure they entered the correct EIN, the business analysts click the Print This
Form button I created for them. The macro behind the button contains a single line of code:
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
The client didn't want the Print Me button itself to appear on the printout. To suppress it, I right-clicked on
the button, went to Format Picture | Properties and deselected the checkbox labeled Print Object.
Room for growth
The client tried to create his own Excel solution. However, like many inexperienced spreadsheet
designers, he wasn't aware of all of his options. For instance, when I proposed storing the mainframe
data and the location data in the same Excel notebook, he commented that he didn't know you could use
VLOOKUPs in one sheet that referred to a range in another sheet. He assumed he'd have to store the
35,000-row database and his form in the same sheet.
The trick I shared is using the name of the sheet, instead of a named range, as the VLOOKUP's data
source. (That way, the client can add rows of new data without worrying about updating the range.) For
example, here's one of the formulas in which I used VLOOKUP to pull data from another sheet:
=VLOOKUP($A7,OurLocations,11,FALSE).
In the future, when the client decides that he needs to pull information from a third source to fill in a blank
on his claim form, he probably won't have to c all me in. All he has to do is insert a new sheet, copy the
new data in the sheet, and add some new VLOOKUPs to his form.
Generate random passwords in Excel
By Gregory Harris | Originally published on TechRepublic Aug. 15, 2001:
http://www.techrepublic.com/article.jhtml?id=r00320010815hrs01.htm
For IT pros, security is an ever-present concern in the enterprise. For others, including young and
inexperienced users, security is often an afterthought.
For example, a network specialist I know recently mentioned problems he has experienced with users
who choose their own passwords. He mentioned users who select their favorite sports team, a password
that can be easily guessed. The alternative, assigning unique passwords for hundreds of users, was a
daunting task.
Fortunately, Microsoft Excel offers a solution. By combining a series of worksheet functions, you can
generate a random, eight-character password with one keystroke. Even better, the password generator
lets you combine uppercase and lowercase letters with numbers to make the password even more
difficult to guess.
Download the password generator
Click here to download a copy of the password generator spreadsheet from TechRepublic. A copy of this
spreadsheet has also been included with this download under the filename password_generator.xls to
save you time and effort. After opening the spreadsheet, simply press the [F9] key to generate a random
password that can be assigned to users.
As you can see, Excel makes it easy to generate random passwords on the fly. Of course, convincing
your users to adopt them instead of something more easily cracked is your next task. And beware, some
users may want to write down their random password and keep it near their PC, a strategy that defeats
the purpose.
How the password generator works
The following information about how I designed the spreadsheet should be helpful if you want to alter the
design to generate passwords that are even more “random.” Here is the method I used to combine
several Excel functions (see Figure A) to build the password generator.
Figure A
Function
Purpose
RAND()
Gen erate a random number within a given range
IF()
CHAR()
Test the generated number to determine the character type
Returns the character with the ASCII number provided in the argument
CONCATENATE() Combines the characters in eight cells into an eight-character password
The heart of the random password generator is the RAND() function. By itself, the function returns a
decimal value between 0 and 1. However, if you multiply this number by a particular value, you can
generate a number within a specified range. For this spreadsheet, I wanted an equal chance of
generating an uppercase letter, a lowercase letter, and a number.
To begin, I want to generate a number between one and 15 using this code:
=RAND()*(15-1)+1
Next, I used nested IF functions to provide three possibilities: If the number is between one and five, we’ll
refer to cell I100, where we’ll generate the value for a numeric character. If it’s greater than five, we’ll use
another IF function to see if we’ll use an uppercase (6-10) letter by referring to the value in cell G100 or a
lowercase (11-15) letter by using the value in cell H100. With the RAND statement in cell F100, the
function in cell E100 looks like this:
=IF(F100>5,IF(F100>10,G100,H100),I100)
Next up are a trio of RAND() functions to generate the ASCII values of numbers and letters. By consulting
an ASCII table, we know that the codes for numbers are between 48 and 57, lowercase letters are
between 97 and 122, and uppercase letters are between 65 and 90. The functions to generate these
number ranges are, respectively:
=RAND()*(57-48)+48
=RAND()*(122 -97)+97
=RAND()*(90-65)+65
Now that our IF statement in cell E100 returns a number from one of these three ranges, it’s time to use
that value to generate an ASCII character. In cell A100, we place a CHAR() function with the cell address
of our IF statement in the parentheses:
=CHAR(E100)
Cell A100 will now contain a number from zero to nine, a lowercase letter, or an uppercase letter. If you
simply fill the IF, CHAR*(), and RAND() statements down seven rows, you’ll get a matrix of cells in the
range A100:A107 that will form your password.
Now all we need is a CONCATENATE() function in cell A110 to assemble the password from those eight
cells. It looks like this:
=CONCATENATE(A100,A1 01,A102,A103,A104,A105,A106,A107,A108,A109)
Putting it all together
Here’s how to combine the functions into a spreadsheet. Place the RAND() functions into cells F100:F107
to obscure the spreadsheet’s workings. A message to the user at the top of the screen and a simple cell
reference (=A110) provides the eight-character password. Figure B shows the final spreadsheet. (We’ve
hidden the intervening blank rows so you can see all the active cells.)
To use the spreadsheet to generate random passwords, all you have to do is press F9, which causes
Excel to recalculate the random numbers. If you wanted to weigh the possibility of uppercase or
lowercase letters or numbers more heavily, you can adjust the values in the nested IF functions or alter
the values to eliminate one type of character altogether.
Figure B
Press [F9] to generate an eight-character password.
Download this handy spreadsheet
Click here to download a copy of Gregory Harris' password generation spreadsheet. You will need a file unzip utility
such as PKZIP or WinZipto extract the download file. You will also need Microsoft Excel 2000 to view the
spreadsheet. A copy of this spreadsheet has also been included with this download under the filename
password_generator.xls.
Field CodeChanged
Field CodeChanged
Quickly sort and total your data with Excel’s Data-Subtotals
By Mary Ann Richardson | Originally published on TechRepublic June 6, 2001:
http://www.techrepublic.com/article.jhtml?id=r00320010606mar01.htm
When I decided to hire a couple of part-timers to help me with my business, my goal was to save time by
having them take over some routine jobs for me. But in order to make it worth my while, I had to ensure
that the payroll tasks involved wouldn’t cancel out any benefits I derived from their employment.
For two part-time workers, I figured that the simplest way to keep records of their time and paychecks was
to use the database feature of Excel 2000. It was easy to set up the worksheet to record their hours and
pay each week. After that, all I needed was a straightforward way to sort and total each employee's pay at
the end of every month. I found my answer in Excel’s Data-Subtotals menu. Using Data-Subtotals, I could
quickly sort, subtotal, and get a monthly summary. This article uses a similar example to help you train
your end users to employ the Subtotals menu to quickly "add up" their Excel data.
Set up the database
Figure A shows an example of a portion of the database used to enter the employees’ hours and
calculate their weekly pay. (Note that all numbers are fictitious and used for demo purposes only.)
Figure A
Using the database shown in Figure A to enter the weekly payroll data worked fine, but it could not, in its
present form, be used to calculate the monthly or quarterly data. While I could have set up the necessary
database functions to sort and total each employee's pay, there was simply not enough time. Instead, I
turned to the Data-Subtotals menu and found it could perform all the calculations I needed without having
to enter a single function.
Sort the data
To calculate each employee’s earnings for the month, I first had to group or sort the records by employee.
Like all operations performed on an Excel database, Sort requires that at least one cell within the
database be selected. In this example, I selected A1, but any cell in the database could be selected. Then
I clicked on Data in the menu bar and selected Sort from the submenu (see Figure B).
Figure B
Clicking on Sort displayed the Sort dialog box.
Figure C
As shown in Figure C, under Sort By, I chose the Employee field and then clicked the OK button. The
results, sorted by employee, are shown in Figure D.
Figure D
Sum the sorted data
With the employees’ records sorted and Cell A1 still selected, I was ready to use Subtotals to obtain their
monthly totals.
First, I clicked on Data in the menu bar, and then I selected Subtotals from the submenu, as shown in
Figure E.
Figure E
Clicking on the Subtotals menu displayed the Subtotal dialog box, as shown in Figure F.
Figure F
To direct Excel to separately add each employee’s weekly gross pay for the month of April, I selected:
1.
Employee as the field in the At Each Change In box to group the records by employee.
2.
Sum as the function to use in the Use Function box.
3.
Gross Pay in the Add Subtotal To list box, making sure that no other check boxes other than
Gross Pay were selected. Excel has a habit of trying to anticipate your wishes.
After clicking the OK button, I got my results (see Figure G).
Figure G
To make it even easier to see the results, I clicked on the outline level 2 symbol on the far left of the
screen. This displayed only the summarized data I needed to write the chec ks, as shown in Figure H.
Figure H
If you don’t see the outline symbols when you use Subtotals, click Options on the tools menu, then click the View tab, and
then select the Outline Symbols check box.
Return to data entry
When I complete my payroll for the month, I return the worksheet to the original format I used for data
entry. To do that, I bring up the Subt otal dialog box again by clicking Data and then Subtotals, as shown
in Figure I .
Figure I
Next, I click on the Remove All button to return to the data entry sheet, shown in Figure J.
Figure J
During May, I can use this same worksheet to add the weekly payroll records for each employee.
Nesting subtotals
At the end of May, I want to summarize the records not only by employee but also by month. To do that, I
make use of nesting subtotals. I follow the same procedure as above, with one exception: After running
Subtotals with Employee selected in the At Each Change In box, I run Subtotals again, only with the
Month field selected in the At Each Change In box. The results after this second run are shown in Figure
K.
Figure K
The results show each employee’s total earnings for the months of April and May, as well as a grand total
for both employees for the two months. On June 30, 2001, when I perform this operation again, the grand
total will come in handy in preparing my quarterly tax returns.
Using Subtotals has helped me perform my payroll tasks quickly and effectively. But Sum is not the only
function Subtotals can help you with. Subtotals also lets you use the Count, Average, Max, Min, Product,
CountNums, StdDev, StdDevp, and Var functions to quickly perform calculations on your data.
Use real-life examples to teach Excel data tables
Mary Ann Richardson | Originally published on TechRepublic Feb. 26, 2001
http://www.techrepublic.com/article.jhtml?id=r00320010226mar02.htm
Unless they are bankers or accountants, most of my Excel students are less than enthusiastic when it
comes to learning data tables. They find it hard to relate to the complicated business problems typically
used to introduce data tables in most course materials. Data tables take a lot of up-front setup work
before they can be used for what-if analysis, so students are naturally reluctant to go through all that
trouble if the results have no meaning for them. Here is a short lesson in one-variable data tables that
may make this technique more relevant to your students.
Can I afford my dream car?
For this demo, I want to determine whether I can afford my dream car—a 1999 low -mileage, fully loaded
Lexus priced at $34,000. For that, I will need to know what my monthly payment would be.
Excel’s PMT function can help me do just that. But first I need to give PMT the following data: the interest
rate of the car loan, the term of the loan in months, and the amount of the loan. These are entered into
the function as follows:
PMT(interest_rate,term -in-months,loan_amount)
Searching the Internet, I learn that the current average used car loan rate was 9.88 percent for 36 months
with 20 percent down.
To make this data available to the PMT function, I enter 9.88 percent for the used car rate in D3 and 36
for the term of the loan in D4. For the loan amount, I enter $27,200 in D5. This is the price of the car I am
interested in minus the required 20 percent down payment of $6,800 (see Figure A) .
Figure A
The next step is to enter the PMT function that references these cells, as shown in Figure B. Because
the payments are made monthly, D3 is divided by 12. (If payments were made quarterly, D3 would be
divided by 4; if semiannually, by 2; etc.)
Figure B
Excel calculates $876.14 for the monthly payment, as shown in Figure C.
Figure C
New or used?
Paying close to $900 a month for a used car seems a bit risky. What if I use the same down payment to
take out the same loan on a new car? Would it be worth sacrificing a few luxury options to get a new car
rather than an older one that was fully loaded? Before I check out a dealer, I need to see what the
difference in payments would actually be. My research shows that the average rate for a 36-month loan
on a new car loan varies according to the borrower’s credit rating and is even less than the used car rate
if your credit is good:
•
New car loan rate with good credit: 8.99 percent
•
New car loan rate with fair credit: 10.99 percent
•
New car loan rate with poor credit: 13.95 percent
Using the one-variable data table, I can compare the monthly payments on a new car loan for $27,500 for
all three rates.
Setting up the one -variable table
To build the data table, list the rates for a new car in a column, as shown in Figure D.
Figure D
Next to the New Car Rates column, add a second column labeled Monthly Payment (see F9 in Figure E).
Excel will display the results for each loan rate in this column.
Figure E
Next, enter =D6 in cell F10. This tells Excel to use the PMT function in D6 to calculate the new car loan
payments (see Figure F).
Figure F
The next step is to select the cells that make up our one-variable data table, as shown in Figure G.
Figure G
Selecting these cells provides Excel with most of the information it needs to complete the table: namely,
the three values for the interest rate variable and the PMT function that will be used to calculate the
monthly payments for each of those values. All that’s left is to identify which variable in the PMT function
should be replaced with the values in the cells of the New Car Rates column. To do that, click Data in the
menu bar and then click Table in the drop-down list, as shown in Figure H.
Figure H
This will bring up the Table dialog box. To tell Excel to replace the variable D3 in the PMT function with
the values in the New Car Rates column, D3 is entered as the Column Input Cell in the Table dialog box
(see Figure I).
Figure I
After clicking OK, the results are displayed in the Monthly Payment column (see Figure J).
Figure J
The data table has confirmed my original assumption: If I can sacrifice a few options, I actually pay less
per month for this year’s model (provided my credit is good) than I would for the fully loaded used car.
Even if my credit is fair, the difference in the monthly payments between the new and used models is only
about $14.00.
One -variable vs. two-variable data tables
Now that the students know how to set up a one- variable table, they can use it to see if they can afford
their own dream cars, using actual interest rates from their local banks. This example shows how helpful
data tables can be when making decisions that involve only one changing factor: in this case, the interest
rate. However, suppose we wanted to compare three different models, one more expensive than the
other, against varying interest rates. In my next lesson, I’ll show you how two-variable data tables can be
used to decide whether or not we should settle for less than our dream car.
Teach two-variable Excel data tables with real-life examples
By Mary Ann Richardson | Originally published on TechRepublic March 2, 2001:
http://www.techrepublic.com/article.jhtml?id=r00320010302mar02.htm
When teaching Excel classes, I’ve found that it pays to use real-life examples to keep users interested. In
my recent article “Use real- life examples to teach Excel data tables,” I showed how to use Excel’s onevariable data table to compare the payments on a 36- month, used-car loan with those on the same loan
for a new car. We found that, because rates are generally lower for new cars, when we applied the same
loan amount toward a new car instead of a used one, we would actually save a few dollars a month.
The trade-off was that we would have to settle for a low -end model, minus some luxury options that would
have come with the older model, which was a 1999 fully loaded, low -mileage Lexus. Or would we? Unlike
used-car loans, which are limited to a 36-month term, new -car loans can be extended over 48 months.
For this data table lesson, we will use the two-variable data table to see if, by extending the payments, we
can afford a more luxurious model.
Setting up the PMT function
To see how extending the term can help us, let’s first use the PMT function to determine what the monthly
payment would be if we took the same $34,000 we were going to spend on the fully loaded used car and
applied it to a new -car loan. Our research indicates that the current average rate on a 48- month, new-car
loan is 9.10 percent. If we apply the same $6,800 down payment to the new -car loan, the loan amount
would again be $27,200. To find out the monthly payment, we first enter the average interest rate, the
term of the loan, and the amount of the loan in an Excel worksheet, as shown in Figure A.
Figure A
The next step is to enter the PMT function that references these cells, as shown in Figure B. Because
the payments are made monthly, E2 is divided by 12. (If payments were made quarterly, E2 would be
divided by 4; if semi-annually, by 2; etc.)
Figure B
Excel calculates the monthly payment to be $678.17, which is considerably less than $876.14, the
monthly payment we had previously calculated for the used -car loan (see Figure C).
Figure C
Let’s go shopping!
Now that we’ve found that we can substantially reduce our payments by extending the term of the loan to
48 months, we are now ready to go shopping for that new car. What we find is that the starting price of a
2001 model is $30,500. If we add some options to it, we can get a pretty nice car for $38,555.
Nevertheless, the model comparable to our used car, in terms of options, costs $54,005. Can we afford
it? Checking out our local banks, we find a range of interest rates available for 48 -month, new -car loans.
We decide to limit our comparison to the three lowest interest rates, which are as follows:
Bank A 7.99%
Bank B 8.99%
Bank C 9.24%
We now have all the information we need to set up the two-variable data table.
Setting up the two-variable data table
The first step in setting up the two-variable data table is to enter the values for the first variable, in this
case, the 48-month interest rates of our local banks. These are entered into the first column of the data
table, as shown in Figure D.
Figure D
Next, we enter the values for the second variable, which are the loan amounts for the three cars under
evaluation. When we apply the $6,800 down payment to the low -end model, which we’ll call Car A, the
loan amount is $23,700 ($30,500 minus $6,800). Applying the same down payment to the midrange
model, or Car B, the loan amount is $31,755 ($38,555 minus $6,800). Likewise, for the high-end model,
Car C, the loan amount is $47,205 ($54,005 minus $6,800). These values are entered into the first row of
the data table, as shown in Figure E.
Figure E
Next, enter =E5 in cell D9. This tells Excel to use the PMT function in E5 to calculate the new -car loan
payments (see Figure F).
Figure F
The next step is to select the cells that make up the two-variable data table, as shown in Figure G.
Figure G
Selecting these cells provides Excel with most of the information it needs to complete the table— namely,
the three values for the interest-rate variable, the three values for the loan-amount variable, and the PMT
function that will be used to calculate the monthly payments for each of those values. All that’s left to do is
to identify which variable in the PMT function should be replaced with the values in the cells of the New
Car Rates column and which variable should be replaced with the values in the cells representing the
loan amounts for each car. To do that, click Data in the Menu Bar and then click Table in the drop-down
list, as shown in Figure H.
Figure H
This will bring up the Data Table dialog box. To tell Excel to replace the variable E4 in the PMT function
with the values in the first row of the data table, E4 is entered as the Row input cell in the Data Table
dialog box. Likewise, to tell Excel to replace the variable E2 in the PMT function with the values in the
New Car Rates column, E2 is entered as the Column input cell in the Data Table dialog box (see Figure
I).
Figure I
After clicking the OK button, the monthly payments for each car for each interest rate are displayed (see
Figure J).
Figure J
Using the two-variable data table
The results for Car B confirm that by applying the same down payment and extending the term of the
loan, we can lower the monthly payments by as much as $100 a month over that of a used car, without
having to sacrifice too many luxury options. But what if we extended the term to 60 months? Or 72
months? Now that we have set up the data table, we can answer both these and similar w hat-if questions,
simply by plugging in the appropriate data.
Teach users to manipulate data with Excel pivot tables
Mary Ann Richardson | Originally published on TechRepublic Dec. 18, 2000:
http://www.techrepublic.com/article.jhtml?id=r00320001218det03.htm
I recently read an article that ranked Excel pivot tables among a list of functions that users were forced to
buy but never used. Yet, the most popular demos I have wit nessed at trade shows were those that
involved dragging and dropping data items onto a designated area of a screen to obtain answers to
pressing business-critical questions (e.g., which products are making money and which aren’t or which
stores were not meeting their sales goals). What seemed to attract the show attendees to such software
was the ability to find answers with just a few clicks of the mouse. Here’s a quick way to teach your users
how Excel pivot tables can be just as functional and easy to use.
Learning pivot tables without mastering databases
Most course materials in Excel don’t let students near pivot tables until they have mastered creating a
database in a spreadsheet. Users also must learn to use a form to enter data into the database, sort that
data, filter the data, add validation checks, and so on. The majority of users learning Excel probably won’t
build or enter data into the databases that contain their needed information. Most of the databases they
will use pivot tables for aren’t even created in Excel but will be downloaded off of a server over a
company network or the Internet. These users simply need an answer to a question, and they need it fast.
Start with something simple
Rather than introducing pivot tables to students with a complex lesson on database creation, begin by
showing them a typical database in Excel from which they can begin asking questions. Keep the
database small—all the records should be visible on the screen without scrolling. Likewise, use an
absolute minimum of fields, i.e., only the ones you will actually need in your pivot table demo. The
database shown in Figure A fits these requirements. Also, it is a good idea to presort the database to
make it easier for the student to check the pivot table results against the actual data in the table.
Figure A
This database has been sorted by division.
After pointing out the various fields of data contained in this database, suggest some questions that the
information in the table can answer. For example, how does the average salary of female employees
compare with that of the male employees? Then walk users through the PivotTable Wizard. First, have
them select the entire database. Next, select Data in the menu bar, followed by PivotTable And
PivotChart Report… in the drop-down menu (see Figure B) .
Figure B
Select PivotTable And PivotChart Report… from the drop - down menu.
Selecting the PivotTable And PivotChart Report… brings up the PivotTable And PivotChart Wizard as
shown in Figure C.
Figure C
The PivotTable And PivotChart Wizard
At this point, select the defaults by clicking the Next button. Since you have already chosen Microsoft
Excel List Or Database to analyze and have already selected that list, Step 2 of the Wizard is already
completed for you, as shown in Figure D.
Figure D
Choosing the defaults takes care of Step 2 of the Wizard.
Clicking the Next button in Step 2 Of 3 of the Wizard brings up the next dialog box. For this first demo, we
will place the pivot table on a new worksheet by clicking on the Finish button (see Figure E).
Figure E
This piv ot table will be on a new worksheet.
After the Finish button is clicked, the Wizard sets up the pivot table on a new worksheet. Note that there
is a new toolbar that lists the five data fields from the database. Since our objective is to compare the
salaries of the male employees with the female employees, we will drag and drop the Gender field to the
box that says Drop Row Fields Here. Next, we will drag and drop the Salary field to the Drop Data Items
Here box, since this is the data we will be averaging (see Figure F).
Figure F
Each of these boxes will hold specific data for your pivot table.
After dragging and dropping both fields as indicated, the following pivot table shown in Figure G is
displayed.
Figure G
Here‘s the finished product.
Now that the table is built, we can begin asking questions of the data.
Once a table is built, it can be saved to the workbook and used again to reflect changes in the data.
By default, the PivotTable Wizard calculates the Sum Of Salary field. But we need to compare the
average. To change the calculation, we first click on A3 to select the data field and then click on the Field
Settings button in the PivotTable toolbar (see Figure H).
Figure H
Select the Field Settings button in the PivotTable toolbar.
After clicking on the Field Settings button, a dialog box appears. Select Average under the Summarize by:
scroll box (see Figure I).
Figure I
Select Average from the options listed in the Summarize by: scroll box.
After clicking OK, the pivot table will now provide the average salaries for both groups, as well as the
average for all employees (see Figure J).
Figure J
The average salaries for male, female, and all employees are now provided.
In a similar manner, we can choose Max from the PivotTable Field dialog box to get the maximum
salaries for both groups, as shown in Figure K.
Figure K
The maximum salaries for each group of employees are now presented.
Likewise, if we had selected Min, we would get the results shown in Figure L.
Figure L
Now the minimum salaries are displayed.
Present your Excel data with pivot charts
Mary Ann Richardson | Originally published on TechRepublic Dec. 26, 2000:
http://www.techrepublic.com/article.jhtml?id=r00320001226det03.htm
In my previous article, "Teach users to manipulate data with Excel pivot tables,” I described how pivot
tables can be created and used to manipulate data. Although pivot tables a llow us to analyze our data,
they’re not the most appealing way of displaying the results of this analysis. The best way to present our
findings is through the use of a chart, specifically a pivot chart. With pivot charts, we can perform the
same operations we did with pivot tables, but display the results in a manner that provides more impact.
Because the instructions outlined in this article draw heavily on those presented in my previous article, I
highly recommend you read that piece before proceeding.
Creating a pivot chart
First, select the Chart Wizard button in the PivotTable toolbar (see Figure A).
Figure A
Select the Chart Wizard button.
Doing so will immediately bring up the pivot chart on a new worksheet, as shown in Figure B.
Figure B
A pivot chart is worth a thousand words.
We can now manipulate the pivot chart in the same manner as we did with the pivot table, only now the
results will be shown graphically. For example, the pivot chart currently shows the minimum salary for
both groups, as reflected in the pivot table we created in the previous article. To see what the average
salary is, we first double -click the Min of Salary button in the upper left corner. This will bring up the
PivotTable Field dialog box. We then select Average from the Summarize by: scroll box just as we did
when we worked with the pivot table (see Figure C). After clicking OK, the chart will now display the
average salary for both groups.
Figure C
Selecting Average will make the pivot chart display the average salary for both groups of employees.
In addition to changing how the data is calculated, we can also add more fields to the chart by dragging
and dropping them to the Drop More Series Fields Here box located above the legend on the pivot chart
(see Figure D).
Figure D
Add more fields by using Drop More Series Fields Here.
For example, to break down the average salaries for both groups by division, we would drag and drop the
Division field from the PivotTable toolbar to get the results shown in Figure E.
Figure E
The average salaries by division for both groups of employees are now displayed.
Once a pivot chart is created, it can be changed and formatted like any other chart. For example, you can
change the chart type by clicking the Chart Type button in the Chart toolbar. You can also use the Chart
toolbar to make any other formatting changes to your pivot chart.
Figure F
You can customize your pivot chart to meet your specifications.
Practice makes perfect
Now that your students have been shown how pivot tables and pivot charts can be used to analyze and
present data, they should try their new skills with other relatively simple databases, e.g., a 20 -record
customer order database. Just as when we created the pivot table and chart used here and in the first
article, the new database should consist of only those fields that can be used to ask a meaningful
question of the data, such as what is the dollar sum of all orders for each product? In this case, you
should keep the product list to no more than five so that the students can easily check their results
against the data. In the end, students will find that success comes not from clicking the right buttons, but
from asking the right questions!
© Copyright 2026 Paperzz