Just About Excel
Just About Excel
Shortcut key
Enter - Enters the number, text or formula into the active cell.
The Name box displays the name of the active cell or selected cells and can be used to apply a name
to a particular cell range.
The drop-down menu next to the name box can be used to quickly navigate to particular named
ranges.
As you type your formula the text will appear in both the cell and the formula bar.
Inserting a Formula
Rather than entering your formulas through the Formula Bar you can just enter them directly into the
cells.
This is the preferred method for a lot of people who are familiar with the function arguments.
Try to avoid hard coding values into formulas. Enter the data into cells and then reference the cells.
In this very simple example a formula is used in cell D2 to calculate the total of the values in cell B2
and C2.
The advantage of using a formula is that it is updated automatically, when the cells that it refers to
change.
Once you have finished the formula, press Enter to confirm.
After you have pressed Enter the cell will display the result of the formula as opposed to the actual
formula.
If we change the value in cell B2 to 9, the formula is re-calculated automatically and the correct
result is displayed.
The table below shows the formula entered in column B and the result obtained in column C.
All the formulas contain basic operations such as addition, subtraction, multiplication and division.
To represent these operations you use what are called Operators in between your numbers.
When you create a formula you need to include at least one operator.
Using Parentheses
Parentheses are basically brackets. Using brackets in your formulas is a good habit to get into even
when they are not strictly needed because they help to clarify the order and make the formula easier
to understand.
It is also possible to put parentheses within parentheses. When parentheses are nested the ones on the
inside are evaluated first.
When you enter parentheses you will notice that Excel tries to help you by making the matching
parentheses bold as you pass over it with the mouse.
Your parentheses must balance. For every open parentheses there must be a corresponding close
parentheses. If you try to submit a formula which does not contain the same number of open and
close parentheses, Excel will prompt you and tell you that the formula you have entered is incorrect.
Excel will make a suggestion as to what it thinks the formula should be. You can accept the
recommendation or press "No" to edit the formula yourself.
The table below shows the more formulas entered in column B and the result obtained in column C.
String Concatenation Operator
The string concatenation "&" operator is also known as the ampersand.
This operator can be used to join several text strings together into a single string.
When a text string is used within a formula the characters must be enclosed in speech marks " ".
You can use this operator to join any two values (text or numeric) in order to create a single text
string.
The table below shows the more formulas entered in column B and the result obtained in column C.
Note that all the logical operators return either True or False.
Things to Remember
• All formulas must start with an equal sign (=). If you type an equal sign into a cell, Excel assumes
that you are about to enter a formula. If you do not enter an equal sign then Excel will assume you
want to enter a text string.
• Formulas can contain simple mathematical operators, values, cell references and functions.
• There is a strictly order of precedence among the operators which means that certain operations are
performed before others.
• Any expression in a formula that is enclosed within a parentheses is calculated first.
• When copying formulas Relative cell references is the default.
• Workbooks that contain a large number of formulas require a large amount of memory and hence
take longer to open.
• Formulas that contain links (especially to other workbooks) can often cause a real headache.
Step 1 -
Why
should I
use Cell
References
?
Instead of hard typing all the values used in your spreadsheet it is possible to use cell references as
well.
This means that your spreadsheet becomes more dynamic and will change accordingly when the
values in the cells change.
Any formulas that contain cell references that are entered in lowercase or mixed case (i.e. B3:H6)
will be automatically changed to uppercase.
An individual cell can be referenced by an unlimited number of formulas.
A cell reference does not have to containan operator unless you want to use it to perform an
operation.
Excel uses colour coding to help you manage your cell references. Each cell reference and the cell it
refers to are displayed in the same colour.
The colour coding makes it very easy to identify which references in the formula match which cells
on the worksheet.
If you are using the mouse to select cell references to construct your formula, only press the Enter
key to confirm the final formula and not the individual cell references.
Notice that all cell references that refer to other workbooks are inserted as absolute references by
default (see later).
If the referenced workbook is not currently open then the full directory location of the file can be
used.
In this case the directory location and the workbook and worksheet name must be enclosed in single
quotes.
It is possible to type in the cell references directly into your formulas although it is much easier to
use the mouse.
To create a cell reference to another workbook, open the other workbook first and then use the
Window drop-down menu to switch to the other workbook and select the required cell.
When you create a cell reference to a different workbook the actual data is stored in the other
workbook and a copy of the data is just displayed.
The cell references will still update even when the other workbook is closed.
Every time a workbook is opened that contains cell references (or links) to other workbooks you will
be prompted as to whether you want to update these links.
For more information on named ranges, please refer to the Named Ranges section.
Absolute Addressing ( =$A$1 ) - Absolute column reference and Absolute row reference.
For example if the formula "=$B$2" was entered into cell C3 and then cell C3 was copied to cell E5,
the formula would not change and would remain "=$B$2".
You can click and drag any of the coloured boxes to new cells to quickly adjust the cell references
used in the formula.
The four squares in the corners allow you to increase or decrease the range of cells being referred to
by dragging these squares with your mouse.
As you change the cell references you will see the formula changing automatically.
It is important to remember that changing this option will change all the formulas in the active
workbook.
There are two different types of R1C1 Notation. You can have relative references or absolute
references.
Relative References ( R[2]C[2] ) are the default and these always include square brackets around the
numbers.
Absolute References ( R2C2 ) are do not include square brackets around the numbers.
Step 4 - Advantages of R1C1 Notation
Although this is an older style of referencing cells it can prove to be useful.
This notation can be useful when you are more interested in the relative position of a cell rather than
in its absolute position.
Automatic - Calculates all dependent formulas every time you make a change to a value, formula or
name. Any workbook that contains formulas will be automatically calculated when it is opened. This
is the default calculation setting.
Automatic except tables - Calculates all dependent formulas except those in data tables. You can
calculate the formulas in data tables by pressing the "Calc Now" button,
Manual - Calculates only when requested by the user.
Recalculate before save - Calculates all dependent formulas in the worksheet before it is saved.
Calculate Now - Calculates all open worksheets, including data tables, and updates all open chart
sheets.
Calc Sheet - Calculates the active worksheet and any charts and chart sheets linked to this worksheet.
All these settings are workbook specific but it is the first workbook that is opened that determines
what the settings are. Opening subsequent workbooks will not change the options.
For more information about the Calculation tab of the (Tools > Options) dialog box, please refer to
the Calculation Tab page.
Things to Remember
• Any data pasted from the clipboard will not have automatic formulas applied to it.
Step 1 - Finding any Formula
Errors
Sometimes when you enter a formula an error will occur. This is to indicate that the formula syntax
is incorrect.
If this error occurs press OK to be taken back to the formula bar. You can either correct the formula
or press ESC to remove the formula completely.
This error may be caused by missing parentheses or incorrect arguments being passed to functions
(e.g. passing a string when it is expecting a number).
To quickly locate any cells that contain errors, select (Edit > GoTo > Special) and tick the Formulas,
Errors checkbox.
The formula is cell B2 tries to divide D2 by D3, which generates an error as division by zero is not
possible.
The formula is cell B3 includes the ISERROR() function as a wrapper around the formula.
3) Obtaining just the workbook name from a folder path and workbook name
A
1 Book1.xls
2 C:\Temp\BetterSolutions.xls
3 C:\Temp\SubFolder\Another Folder\Workbook_Name.xls
=MID(A1,FIND("#",SUBSTITUTE("\"&A1,"\","#",LEN(A1)-
LEN(SUBSTITUTE(A1,"\",""))+1)),LEN(A1))="Book1.xls"
=MID(A2,FIND("#",SUBSTITUTE("\"&A2,"\","#",LEN(A2)-
LEN(SUBSTITUTE(A2,"\",""))+1)),LEN(A2))="BetterSolutions.xls"
=MID(A3,FIND("#",SUBSTITUTE("\"&A3,"\","#",LEN(A3)-
LEN(SUBSTITUTE(A3,"\",""))+1)),LEN(A3))="Workbook_Name.xls"
Step 1 -
What are
Arrays
in
Formula
s?
For more details on array formulas please refer to the Array Formulas section.
It is possible to use arrays in your formulas and the reason you may want to do this is because it lets
you enter the values directly as opposed to having to use cells.
When you use arrays in formulas you do not need to enter them using (Ctrl + Shift + Enter). To enter
the formula press Enter.
All the formulas in column F are equivalent and all return the total 110.
Formulas can work with arrays that are contained in cells, arrays that are constant as well as array
formulas.
Example
illustrating the following
concatenating
finding the first space
finding the next space
removing excess spaces
getting first, middle and last words
Rather than edit all these manually you could opt for a formula based solution.
When you are satisfied that the mega formula is returning the same result you can delete all the
intermediate formulas.
It is often to keep a copy of the intermediate formulas in case you need to make an ammendment to
the formula at a later date.
Conditiona
l Formula
Allows you to perform calculations on only those numbers that meet a certain condition.
To create a condition you can use various comparison operators, such as greater than (>), greater
than or equal to (>=), less than (<), less than or equal to (<=) and equal to (=).
Type a comparison operator, the condition and then a comma.
On the Summary worksheet we want to be able to quickly return the total for all the Regions and for
the months.
It is possible to create 3D formulas which refer to all four worksheets which makes creating a
summary worksheet very easy.
Lets assume that each of the four worksheets contains the following table of data.
Select the cell you want to sum in this case cell "G3".
Enter a close bracket ")" to complete the formula.
Worksheet Functions
It is important to realise that not all the functions will accept a 3D formula.
The following functions can all be used in 3D formulas.
AND The logical AND for any number of arguments.
AVEDEV The average deviation for a list of numbers.
AVERAGE The arithmetic mean of a list or array of numbers.
AVERAGEA The arithmetic mean of a list or array of numbers,
including text and logical values.
COUNT The number of cells with a numeric value in a list or cell
range.
COUNTA The number of non blank cells in a list or cell range.
DEVSQ The sum of squares of deviations of data points from
their sample mean.
LARGE The Kth largest value in an array of numbers.
MAX The largest value in a list or array of numbers.
MAXA The largest value in a list or array of numbers, including
text and logical values.
MEDIAN The median of the numbers in a list or cell range.
MIN The smallest number in a list or range.
MINA The smallest number in a list or range, including text and
logical values
OR The logical OR for any number of arguments.
PERCENTILE The Kth percentile of values in a range.
PRODUCT The product of all the numbers in a list or cell range.
QUARTILE The quartile of a data set.
RANK The rank of a value in a range (in descending order).
SKEW The number representing the skewness of a distribution.
SMALL The Kth smallest value in an array of numbers.
STDEV The standard deviation based on a sample.
STDEVA The standard deviation based on a sample, including text
and logical values.
STDEVP The standard deviation based on an entire population.
STDEVPA The standard deviation based on an entire population,
including text and logical values.
SUM The total value of the numbers in a list or cell range.
SUMSQ The sum of the squares of all the values in a list or cell
range.
TRIM The text string with all spaces removed from the
beginning and end.
VAR The compound variance based upon the numerical values
in the range.
VARA The compound variance based upon the numerical values
in the range.
VARP The variance based on an entire population.
VARPA The variance based on an entire population, including
text and logical values.
Things to Remember
• It is possible to create named ranges for 3D cell references which
can be used to simplify your 3D formulas.
• For more information on 3D named ranges, please refer to the 3D
Named Ranges page.
Protecting your
formulas can prevent
accidental editing and
viewing
In order for a cell to be protected - The worksheet
must be protected and the "Locked" checkbox on the
(Format > Cells)(Protection tab) must also be
checked. (this is the default).
(Format > Cells)(Protection tab) ??
If you only want to protect a few cells - first remove the locked property from all the cells. Select
(Ctrl + "A") and clear the locked check box. This will mean that even if the worksheet is protected
the cells will not be.
Find the individual cells that contain formulas you want to hide and change the property back to
Locked.
If you want to protect a few formulas without protecting the whole sheet select the cells and choose
(Data > Validation), Select custom in the first window and type (="") in the second window.
A few
facts
about
formula
s
A formula cannot include more than 1,024 characters.
If you have formulas linking to a workbook and when this workbook is open you press (File >
SaveAs) to create a backup, you will automatically change the link formulas to refer to this new file.
It is possible to enter fractions but always precede with a space to ensure that Excel does not interpret
it as a date.
When entering your formulas you can press F3 when you are in the formula bar to quickly insert a
named range.
To quickly copy a formula down of a cell down that have data in either of its surrounding columns
just double click on the fill handle in the bottom right corner of the cell. ???
If you have really complicated formulas you may find it useful to edit the formula directly in the cell.
Press F2.
What does the "(Calculate)" mean in the status bar ??
You can mess up your links by renaming the source workbook when the dependent workbook is not
open.
You can easily create link formulas that refer to cells in other workbooks. If the workbook name in
the reference included one or more space you must enclose it (and the worksheet name) in single
quotation marks.
You can quickly select all the cells that contain formulas by using the (Edit > GoTo > Special) and
selecting Formulas ??
By default if a worksheet is protected the formulas can still be viewed. Before protecting the
worksheet you must indicate if you want the formulas to be hidden. (Format > Cells) (Protection tab)
select the hidden checkbox for all your cells. To ensure changes can t be made ensure the locked
checkbox is checked.
Debugging Formulas
If you are checking that formulas are correct, you can create a new window of the same workbook
and view the values in one window and the formulas in another window. You can quickly toggle
between the values and formulas by pressing ??
If you have a large number of intermediate formulas you can combine them into one large formula.
The advantage of this is that recalculation of the spreadsheet is faster.
The quickest way to convert formulas to values is to move the formulas one cell to the right, and then
hold down the right mouse button, when you drag them back to the original position. Choose "copy
as values" from the shortcut menu ??
If you enter a large formula and it is not correct, press the OK to edit the formula, press HOME to
take you to the start of the formula and enter an apostrophe. This will enter your formula as text and
allow you to edit it easily
You can examine the components of a large formula by dragging the pointer to highlight part of the
formula and pressing the F9 key to evaluate only the highlighted part. Remember to press the ESC
key afterwards.
You can quickly select all the cells that contain formulas by choosing (Edit > GoTo > Special) and
select formulas ??
The N() worksheet function is a way to include a text description into a cell containing a formula,
without it affecting the formula.
You probably won't use the R1C1 notation as your default although it is very useful for checking
your copied formulas. Every cell should have the same R1C1 formula.
You can retrieve data from a file without actually opening it (e.g. use the formula
"=[File_Name.xls]Sheet1!A1").
You can easily display leading zeros by using a custom number format "000000". This will mean
that 6 numbers are entered and any that are not entered will be zero.
You may find it helpful when editing cell references that link to other worksheets to temporarily
change the worksheet name to a shorter one. Making changes with a shorter worksheet name is easier
and the name can then be changed back afterwards.
Shortcut Keys
(Ctrl + ~) - You can toggle between displaying the values and formulas by pressing
(F2, F9) - Pastes a formula as values.
(Ctrl + Home) - Moves to the beginning of a formula when you are editing it.
(Ctrl + End) - Moves to the end of a formula when you are editing it.
Financial Formulas - by Category
For convenience, I've listed all of the Excel Financial functions, with a * next those that
are only available after installing the Analysis ToolPak (To install, go to Tools > Add-ins
> and select Analysis ToolPak).
Depreciation Formulas
• DB - Fixed-Declining Balance
• DDB - Double-Declining Balance
• SLN - Straight-Line Depreciation
• SYD - Sum-of-Years' Digits
• VDB - Variable Declining Balance
• * AMORLINC - (for the French accounting system) Depreciation for each
accounting period
• * AMORDEGRC - (for the French accounting system) Uses a depreciation
coefficient
Answer: To create a hyperlink to another cell in your spreadsheet, right click on the cell
where the hyperlink should go. Select Hyperlink from the popup menu.
When the Insert Hyperlink window appears, click on the "Place In This Document" on
the left. Enter the text to display. In this example, we've entered "Hyperlink to cell A5".
This is the value that will be displayed in Excel.
Next enter the cell reference that the hyperlink points to. We've chosen to link to cell A5.
Click the OK button.
Now when you return to the spreadsheet, you should see the hyperlink.
If you click on the hyperlink, your active cell should become cell A5.
Excel: Delete all hyperlinks on a sheet
Question: I've had a hyperlink problem in my Excel files for ages: false hyperlinks had
crept in (even in empty cells) and were multiplying regularly whenever I inserted new
lines. How can I delete all hyperlinks in a sheet at once and not have to delete them cell
by cell?
Answer: You will need to create a macro to delete the hyperlink addresses in your Excel
sheet.
Open your Excel spreadsheet that you wish to remove the hyperlinks from. Press
<ALT>-F11 to go to the Visual Basic editor. Create a new module. You can do this by
selecting Module under the Insert menu.
Sub RemoveHyperlinks()
End Sub
Close the Visual Basic editor window by selecting "Close and Return to Microsoft Excel"
under the File menu.
Now, go to the sheet that contains the hyperlinks that you wish to delete. Here is an
example of a sheet with multiple hyperlink addresses:
Under the Tools menu, select Macro > Macros. Highlight the macro called
"RemoveHyperlinks" and click on the Run button.
Now your hyperlinks should be deleted as you can see by the example below:
If you need to remove hyperlinks from other sheets, just repeat the steps above.
Question: I have an Excel worksheet that has the first 6 rows frozen. In the first 6 rows,
I have hyperlinks to different cells in column B. When I click the hyperlinks, Excel tends
to show the cell at the bottom of the viewing page.
I want the cell that the hyperlink refers to be displayed in the next row after the frozen
rows. Can this be done?
Below, we have an Excel spreadsheet with the first 6 rows hidden. In cell B5, we've
created a hyperlink to cell B30. When we click on the hyperlink in cell B5, the
spreadsheet looks as follows:
The hyperlink is at the bottom of the viewing area in the spreadsheet. We want to see row
30 directly under row 6.
To fix this, select Options under the Tools menu. When the Options window appears,
click on the Transition tab. Then select the option called "Transition navigation keys".
Click on the OK button.
Now when you click on the hyperlink in cell B5, your spreadsheet should look as
follows:
Excel: VLookup Function
In Excel, the VLookup function searches for value in the left-most column of
table_array and returns the value in the same row based on the index_number.
value is the value to search for in the first column of the table_array.
index_number is the column number in table_array from which the matching value must
be returned. The first column is 1.
not_exact_match determines if you are looking for an exact match based on value. Enter
FALSE to find an exact match. Enter TRUE to find an approximate match, which means
that if an exact match if not found, then the VLookup function will look for the next
largest value that is less than value.
Note:
If you enter FALSE for the not_exact_match parameter and no exact match is found, then
the VLookup function will return #N/A.
For example:
=VLookup(10251, A1:B21, 2,
would return "Tofu"
FALSE)
=VLookup(10251, A1:C21, 3,
would return $18.60
FALSE)
=VLookup(10248, A1:B21, 2,
would return #N/A
FALSE)
=VLookup(10248, A1:B21, 2, would return "Queso
TRUE) Cabrales"
Question: In Excel, I'm using the VLookup function to return a value. I want to sum the
results of the VLookup, but I can't because the VLookup returns a #N/A error if no match
is found. How can I sum the results when there are instances of #N/A in it?
=IF(ISNA(VLOOKUP(E2,$A$2:$C$5,3,FALSE)),0,VLOOKUP(E2,$A$2:$C
would return 0
$5,3,FALSE))
First, you need to enter a FALSE in the last parameter of the VLookup function. This will
ensure that the VLookup will test for an exact match.
If the VLookup function does not find an exact match, it will return the #N/A error. By
using the IF and ISNA functions, you can return the Unit Price value if an exact match is
found. Otherwise, a 0 value is returned. This allows you to perform mathematical
operations on your VLookup results.
Question: I have a list of #s in column A (lets say 1-20). There is a master list in another
column that may not include some of the column A #s. I want a formula in column B to
say (if A1 exists in the master list, then "Yes", "No". Is this possible?
Answer: This can be done with a formula that utilizes a combination of the VLookup
function, IF function, and ISNA function.
Based on the spreadsheet above:
would
=IF(ISNA(VLOOKUP(A2,$D$2:$D$185,1,FALSE)),"No","Yes") return
"No"
would
=IF(ISNA(VLOOKUP(A5,$D$2:$D$185,1,FALSE)),"No","Yes") return
"Yes"
First, you need to enter a FALSE in the last parameter of the VLookup function. This will
ensure that the VLookup will test for an exact match.
If the VLookup function does not find an exact match, it will return the #N/A error. By
using the IF and ISNA functions, you can return a "Yes" value if an exact match is found.
Otherwise, a "No" value is returned.
Question: Is there a simple way in Excel to VLookup the second match in a column? So,
for instance, If I had apple, pear, apple listed in the column (each word in a separate cell),
would there be a way to look up the values to the right of the second "apple"?
Answer: This can be done with a formula that utilizes a combination of the Index
function, Small function, Row function (all in an array formula).
If you wanted to return the quantity value for the second occurrence of apple, you would
use the following array formula:
=INDEX(A2:C6,SMALL(IF(A2:C6="apple",ROW(A2:C6)-
ROW(A2)+1,ROW(C6)+1),2),2)
When creating your array formula, you need to use Ctrl+Shift+Enter instead of Enter.
This creates {} brackets around your formula as follows:
{=INDEX(A2:C6,SMALL(IF(A2:C6="apple",ROW(A2:C6)-
ROW(A2)+1,ROW(C6)+1),2),2)}
If you wanted to return the quantity value for the third occurrence of apple, you would
use the following array formula:
=INDEX(A2:C6,SMALL(IF(A2:C6="apple",ROW(A2:C6)-
ROW(A2)+1,ROW(C6)+1),3),2)
When creating your array formula, you need to use Ctrl+Shift+Enter instead of Enter.
This creates {} brackets around your formula as follows:
{=INDEX(A2:C6,SMALL(IF(A2:C6="apple",ROW(A2:C6)-
ROW(A2)+1,ROW(C6)+1),3),2)}
If you wanted to return the bin # for the second occurrence of apple, you would use the
following array formula:
=INDEX(A2:C6,SMALL(IF(A2:C6="apple",ROW(A2:C6)-
ROW(A2)+1,ROW(C6)+1),2),3)
When creating your array formula, you need to use Ctrl+Shift+Enter instead of Enter.
This creates {} brackets around your formula as follows:
{=INDEX(A2:C6,SMALL(IF(A2:C6="apple",ROW(A2:C6)-
ROW(A2)+1,ROW(C6)+1),2),3)}
If you wanted to return the bin # for the third occurrence of apple, you would use the
following array formula:
=INDEX(A2:C6,SMALL(IF(A2:C6="apple",ROW(A2:C6)-
ROW(A2)+1,ROW(C6)+1),3),3)
When creating your array formula, you need to use Ctrl+Shift+Enter instead of Enter.
This creates {} brackets around your formula as follows:
{=INDEX(A2:C6,SMALL(IF(A2:C6="apple",ROW(A2:C6)-
ROW(A2)+1,ROW(C6)+1),3),3)}
As you'll shortly see, Pivot Tables can become quite complex. So we'll take it easy and
just design a simple one. But first, what is a Pivot table?
A Pivot table is to a way to extract data from a long list of information, and present it in a
readable form. Remember the data we had from the student scores spreadsheet? You
could turn that into a pivot table, and then view only the Maths scores for each pupil. Or
view just Paul's scores, and nobody else's.
To get a clearer idea of just what a Pivot Table is, examine the one below. You'll be
designing this very Pivot Table yourself shortly.
In this school, there is a test every month (it's a tough school!). The Pivot Table above
shows the marks that Elisa got in January, February, and March. There were tests for only
6 subjects. Notice the black down-pointing arrows in the Pivot Table. On Row 1 we have
Student Elisa. If the black arrow were clicked, a drop-down box would appear showing a
list of the other students. We could click on a student and view the marks he or she
achieved. Or we could select which subjects to view, or choose only one month.
But Excel does most of the work for you, and puts in those drop-down boxes as part of
the wizard. But you'll see how it works.
Before you can construct a Pivot Table, you need some data in list form. We're going to
construct our Pivot Table using only two students, Elisa and Mary. We'll use just three
months worth of data, and six subjects. You'll be glad to know that this has already been
done for you. So download the spreadsheet below:
In the next part, you'll start work on constructing the Pivot Table itself.
The Pivot Table is constructed using a Wizard. To create yours, do the following:
The Range of cells that Excel will include in our Pivot Table is A1 to D37. (You can
change this if you wanted.) Because we clicked in cell A2 to begin with, Excel has taken
that as the first Row of Data. Excel uses the labels from Row 1 as Headings. Excel will
use these for our drop down boxes and data.
Click the Next button on Step Two. Step Three of the Wizard appears. It's a little more
complicated, this time.
We'll accept the default position for the location of the Pivot Table - New worksheet. The
button we're after is Layout. So click the Layout button to see a quite complicated
dialogue box. This one:
The Field Buttons the Wizard is talking about are those four on the right: Month,
Subject, Student and Score. The idea is that you click on a button. Hold down your left
mouse button and drag to an area on the left. We're going to drag one button to the
Column area, one to the Row area, and one to the Data area.
In the Row area, we'll put Month; in the Column area, we'll put Subject, and in the Data
area we'll put Score. We'll do something with the Student button after the Pivot Table has
been constructed.
So do the following:
• Click on Month
• Hold down your left mouse button
• With the mouse button held down, drag the mouse pointer over to the Row area
• Let go of the button when it's there
• A button will appear in the Row area
• The images below show the process in action
Let go of the left mouse button when the pointer is over Row
When you have the Month button in place, drag the Subject button to the Column area,
and the Score button to the Data area. Your dialogue box will then look like this:
Click OK when your dialogue box looks like the one above. You will be taken back to
Step Three of the Wizard. Click the Finish button and you're done. You'll then have a
spreadsheet that looks like this one:
If you don't see the Pivot Table toolbar, click on View > Toolbars > Pivot Table.
I'm sure you'll agree - our Pivot Table is coming along nicely. In the next part, you'll
learn how to manually add a button to a Pivot Table.
We're now going to put the Students button on the Pivot Table. So do the following:
• Locate the Student button on the Pivot Table toolbar, as in the image below:
We're almost there, now. Only a couple more things left to do. First, take a look at the
scores. What the Pivot table is doing is adding all the scores up. That's because of cell
A3. Notice that it says "Sum of Score". We don't want it to do that. An Average is much
better for our purposes.
Some of the scores in the Grand Total Row and Grand Total column will be a bit long.
But you can format the numbers to in the usual way.
We can now take a look at those drop down boxes. We'll start with the Student box.
At the moment, the Student box says All. Click the black down arrow to see the list of
students.
Our two Students are listed there. Click on Elisa, then click the OK button. Notice how
your spreadsheet has changed. It should now only be showing you Elisa's results. Click
the black down arrow in cell B1 again, and click on Mary. Then click the OK button.
Your spreadsheet will change to show only Mary's results.
Try clicking the black down arrow of Subject, in cell B3. You should see this:
All the Subjects have ticks in them. Click on a tick and it will disappear. Try un-ticking a
few of the subjects. Then click the OK button to see what happens.
The Month list in cell A4 shows a similar list with ticks in them. Un-tick a month and see
the results when you click OK.
You can add comments to pivot tables. The one below shows a Comment about Elisa's
English scores:
Another thing you can do is change the type of Pivot Table Report. From the Pivot Table
toolbar, click the Pivot Table button. From the menu that pops up, select Format Report.
Click on any of the formats you like then click OK to see what happens. If you don't like
what you see, click Edit > Undo AutoFormat to get back to your Pivot Table.
And that wraps up this short introduction on Pivot Tables. But they are a good way to
summarise long lists of data. In the next section, we take a look at Excel Forms, and see
how to download data from a web page straight into Excel.
Excel Topics: Pivot Tables
Excel: Create a pivot table
Answer: We'll start by creating a very simple pivot table. The example that follows has
been done in Excel 2000, so the screen may look different if you are using a different
version of Excel. Either way, it will give you a basic understanding of pivot tables.
First, our data that we want to use to populate the pivot table resides on Sheet1.
Under the Data menu, select "PivotTable and PivotChart Report".
A PivotTable wizard should appear. Make sure that the "Microsoft Excel list or database"
and "PivotTable" options are chosen. Click on the Next button.
Select the range of data for the pivot table and click on the Next button. In this example,
we've chosen data from Sheet1.
Select the position to create the new pivot table. It will automatically default to the cell
that was highlighted when you started this process. In this example, we want to create our
pivot table on Sheet2 in cell A1.
Answer: To refresh a pivot table in Excel, select a cell in the pivot table. Right-click and
then select "Refresh Data" from the popup menu.
Excel: Automatically refresh pivot table
when file is opened
Question: How do I get a pivot table to automatically refresh when the Excel
spreadsheet is opened?
Answer: Select a cell in the pivot table. Right-click and then select "Table Options"
from the popup menu.
When the PivotTable Options window appears, check the checkbox called "Refresh on
open". Click on the OK button.
Question: Is it possible to create a button in Excel that will refresh/update multiple pivot
tables?
Answer: Yes, you can refresh multiple pivot tables with a button. To do this:
Sheets("Sheet1").Select
ActiveSheet.PivotTables("PivotTable1").RefreshTable
Sheets("Sheet2").Select
ActiveSheet.PivotTables("PivotTable2").RefreshTable
You will need to replace the Sheet1 and Sheet2 with the names of your sheets and
PivotTable1 and PivotTable2 with the names of your pivot tables.
To find out the name of a pivot table, right-click on the pivot table and select Table
Options.
Excel: Automatically refresh pivot table
when data in a sheet changes
Question: I'm looking for a macro that would automatically refresh a pivot table
whenever data is changed in an Excel worksheet. Is this possible?
Answer: There are several "events" available within an Excel spreadsheet where you can
place VBA code. In your case, we want to refresh the pivot table when the
"Worksheet_Calculate" event fires.
In our spreadsheet, there are two sheets - one is called Data which contains the source
data for the pivot table. Another sheet is called Pivot which contains the pivot table.
On the sheet called Data, we've placed code on the "Worksheet_Calculate" event, so that
whenever the data changes on the "Data" sheet, the pivot table will be refreshed.
Note: This only will work, if you have the spreadsheet set to calculate "automatically".
This is the default for most Excel spreadsheets, but some people turn this feature off.
Macro Code:
The macro code looks like this:
Private Sub Worksheet_Calculate()
End Sub
Answer: Below is a pivot table with a grand total for the column called OrderID.
To remove this column grand total, select a cell in the pivot table. Right-click and then select
"Table Options" from the popup menu.
When the PivotTable Options window appears, uncheck the checkbox called "Grand totals for
columns". Click the OK button.
Now when you return to the spreadsheet, the grand total for the OrderID column will no
longer be visible.
Excel: Remove grand totals for rows
Question: On a pivot table, how do I remove the grand totals for rows?
Answer: Below is a pivot table with a grand total for the row called Product.
To remove this row grand total, select a cell in the pivot table. Right-click and then select
"Table Options" from the popup menu.
When the PivotTable Options window appears, uncheck the checkbox called "Grand
totals for rows". Click the OK button.
Now when you return to the spreadsheet, the grand total for the Product row will no
longer be visible.
Excel: Change pivot table name
Answer: Select a cell in the pivot table. Right-click and then select "Table Options"
from the popup menu.
When the PivotTable Options window appears, enter the new name for the pivot table in
the Name field. Click the OK button. In this example, we've renamed our pivot table to
ExamplePT.
Excel: Do not save data with table layout
Question: After I created a pivot table, the size of the Excel spreadsheet became quite
large. This was due to the fact that the data behind the pivot table was saved with the
table layout. How do I prevent Excel from saving the data with the table layout?
Answer: Select a cell in the pivot table. Right-click and then select "Table Options"
from the popup menu.
When the PivotTable Options window appears, uncheck the checkbox called "Save data
with table layout". Click on the OK button.
Excel: Display pivot table wizard
Question: Once I've created a pivot table, how do I get back to the Pivot Table Wizard?
Answer: To return to the Pivot Table Wizard, select any cell in the pivot table.
Right-click and then select "Wizard" from the popup menu.
You should now see the Pivot Table Wizard.
Excel: Remove subtotals on pivot table
rows
Answer: Select the row heading that you wish to remove subtotals on. Right-click and
then select "Field Settings" from the popup menu. In this example, we've chosen the row
heading called Order ID.
When the PivotTable Field window appears, select the "None" subtotals option. Click on
the OK button.
Now when you return to the spreadsheet, the subtotals for each OrderID are no longer
visible.
Excel: Remove subtotals on pivot table
columns
Answer: Select the column heading that you wish to remove subtotals on. In this
example, we've chosen the column heading called Discount.
Right-click and then select "Field Settings" from the popup menu.
Under subtotals, select the "None" option. Click on the OK button.
Now when you return to the spreadsheet, the subtotals for each Discount are no longer
visible.
Answer: Select a row heading in the pivot table. In this example, we've chosen the row
heading called Order ID.
Right-click and then select "Field Settings" from the popup menu.
When the PivotTable Field window appears, click on the Advanced button.
Under the AutoShow options, select Automatic. Select Top and the number of items that
you wish to view. Now click on the OK button.
In this example, we've chosen the Top 10 values based on the "Sum of Quantity" field.
This will return you to the PivotTable Field window. Click on the OK button.
Now when you view your spreadsheet, you should only see the top 10 values based on
quantity.
Excel: Show Bottom 10 results
Answer: Select the row heading in the pivot table. In this example, we are selecting the
Order ID heading.
Right-click and then select "Field Settings" from the popup menu.
When the PivotTable Field window appears, click on the Advanced button.
Under the AutoShow options, select Automatic. Select Bottom and the number of items
that you wish to view. Now click on the OK button.
In this example, we've chosen the Bottom 10 values based on the "Sum of Quantity"
field.
This will return you to the PivotTable Field window. Click on the OK button.
Now when you view your spreadsheet, you should only see the bottom 10 values based
on quantity.
Excel: Change how errors are displayed
Question: I don't want to see errors in the pivot table. How do I replace all errors with
another value?
Answer: Let's first take a look at an example of an error in a pivot table. This is a picture
of our underlying data for the pivot table. You can see in row 16 that the quantity entry
has an error in it. This could be the result of a vlookup function, for example.
Now when you take a look at the pivot table that uses this data, you can see the error in
the pivot table.
You can replace this error with a more appropriate value. To do this, select a cell in the
pivot table. Right-click and then select "Table Options" from the popup menu.
When the PivotTable window appears, check the checkbox called "For error values,
show". Then enter the value that you wish to see in the pivot table instead of the error.
Click on the OK button. In this example, we've decided to replace the error with a 0.
Now when we return to the pivot table, this is what we'll see.
Excel: Change how empty cells are
displayed
Question: I don't want to see empty cells in a pivot table. How do I replace all empty
cells with another value?
Answer: First, let's explain what an empty cell is. In the example below, we have order #
10253 that does not have any quantity (row 10 in spreadsheet). Therefore, the quantity is
showing as a blank cell.
We'd like to replace all empty cells with the value "n/a". To do this, select any cell in the
pivot table. Right-click and then select "Table Options" from the popup menu.
When the PivotTable window appears, check the checkbox called "For empty cells,
show". Then enter the value that you wish to see in the pivot table instead of the empty
cell. Click on the OK button. In this example, we want all blank cells to show as "n/a".
Now when we return to the pivot table, we see "n/a" as the quantity value for order
#10253.
Excel: Display the fields in the Data
Section in multiple columns
Question: I've created a pivot table in Excel with two fields in the Data Section of the
pivot table. These fields are the sum of the Quantity as well as the sum of the Total cost
of an order. The pivot table seems to be populating the Data Section in a single column
and I want to see the results in two columns.
How can I set up my pivot table so that the Quantity and Total cost (in the data section)
values show up in two columns instead of being listed in one?
Answer: By default, Excel will probably format your data section of your pivot table to
populate all values in one column, as seen below:
In this example, you can see that the "Sum of Quantity" as well as "Sum of Total Cost"
fields are being displayed in one column. To change the pivot table so that each field is in
its own column, first highlight the label called "Data".
Next, while your mouse cursor is over the Data label, click and hold down the Left
Mouse Button. Slowly drag your mouse cursor to the right until you see the mouse cursor
change to a picture similar to the above. This is usually when your cursor is over the label
called Total.
Question: I've created a pivot table in Excel with two fields in the Data Section of the
pivot table. These fields are the sum of the Quantity as well as the sum of the Total cost
of an order. The pivot table seems to be populating the data section in multiple columns
and I want to see the results in a single column.
How can I set up my pivot table so that the Quantity and Total cost (in the data section)
values show up in a single column instead of being listed in two?
Answer: Excel may format your data section of your pivot table to populate your values
in multiple columns, as seen below:
In this example, you can see that the "Sum of Quantity" as well as "Sum of Total Cost"
fields are being displayed in multiple columns. To change the pivot table so that the fields
are populated in a single column, first highlight the label called "Data".
Next, while your mouse cursor is over the Data label, click and hold down the Left
Mouse Button. Slowly drag your mouse cursor to the left until you see the mouse cursor
change to a picture similar to the above. This is usually when your cursor is next to your
Row Section (ie: Order ID field).
Answer: Select the value that you wish to hide. In this example, we are going to order
Order #10249.
Right-click and the select "Hide" from the popup menu.
The Order #10249 is now hidden.
Excel: Display a hidden value
Answer: To explain how to display a hidden value in an Excel pivot table, we'll take a
look at an example. In this case, the entry for Order ID 10249 is hidden.
Click on the arrow to the right of the field that has the hidden value. In this example, the
field that has the hidden value is called Order ID, so we'll click on the arrow to the right
of the Order ID field.
Check the box to the left of the value that you want to display. Click on the OK button. In
this example, we've checked the box for Order ID 10249.
Just to summarize, all checked values are visible in the pivot table and all unchecked
values are hidden in the pivot table.
Now when we return to the pivot table, we can see the details for Order ID 10249.
Answer: To hide empty cells in a pivot table, select the empty cell in the pivot table.
Right-click and select Hide from the popup menu.
Now whenever the OrderID is blank, the data will be hidden in the pivot table.
Excel: Hide zero value lines within a pivot
table
Question: I wonder if you can help, is there a way in which you are able to hide zero
valued lines within a pivot table ? i.e. I have a table with two columns branch name and
stock value and I would like to hide the branches with no value against them - is this
possible ?
Answer: Let's take a look at an example. Below is an Excel spreadsheet that contains
values that are zeros. We want to hide these lines from being displayed in the pivot table.
Right-click in the Pivot table and select Wizard from the popup menu.
When the PivotTable Wizard appears, click on the Layout button.
Drag the STOCK VALUE field to the PAGE section. Click on the OK button.
Answer: Select the row heading that you wish to sort on. Right-click and then select
"Field Settings" from the popup menu. In this example, we've selected the row heading
called Order ID.
When the PivotTable Field window appears, click on the Advanced button.
Under the AutoSort options, select either Ascending or Descending depending on the sort
order that you wish to select. Click on the OK button. In this case, we've chosen to sort
the Order ID field in ascending order.
This will return you to the PivotTable Field window. Click on the OK button.
The GetPivotData function returns data from a pivot table. It can retrieve summary data
from a pivot table as long as the summary data is visible.
pivot_table is generally a named range that has been set up to point to the pivot table.
name is the name of the summary value that you wish to retrieve.
For Example:
Below we have an Excel spreadsheet that has a pivot table on Sheet2. We've set up a
named range called PivotTable that references this pivot table (Sheet2!$A:$E).
The GetPivotData function returns data from a pivot table. It can retrieve summary data
from a pivot table as long as the summary data is visible.
pivot_table is generally a named range that has been set up to point to the pivot table.
name is the name of the summary value that you wish to retrieve.
For Example:
Below we have an Excel spreadsheet that has a pivot table on the sheet called "Pivot
Table". We've set up a named range called team_count that references this pivot table
('Pivot Table'!$A:$C).
=GetPivotData (team_count,"'Team 1' 'Count of
would return 1
B'")
=GetPivotData (team_count,"'Team 2' 'Count of
would return 3
B'")
=GetPivotData (team_count,"'Team 2' 'Count of
would return 12
C'")
Working with Pivot Tables
Contents
PivotTables
Share PivotTables but Not Their Data
Automate PivotTable Creation
Move PivotTable Grand Totals
Efficiently Pivot Another Workbook's Data
PivotTables allow you to pivot data using drag-and-drop techniques and receive results
immediately. PivotTables are interactive; once the table is complete, you very easily can
see how your information will be affected when you move (or pivot) your data. This will
become patently clear once you give PivotTables a try.
Even for experienced PivotTable developers, an element of trial and error is always
involved in producing desired results. You will find yourself pivoting your table a lot!
PivotTables
PivotTables are one of the wildest but most powerful features of Excel that may take
some experimentation to figure out.
We use PivotTables a lot when we develop spreadsheets for our clients. Once a client
sees a PivotTable, they nearly always ask whether they can create one themselves.
Although anyone can create a PivotTable, unfortunately many people tend to shy away
from them, as they see them as too complex. Indeed, when you first use a PivotTable, the
process can seem a bit daunting. Some persistence is definitely necessary.
You'll find that persistence will pay off once you experience the best feature of
PivotTables: their ability to be manipulated using trial and error and immediately show
the result of this manipulation. If the result is not what you expect, you can use Excel's
Undo feature and have another go! Whatever you do, you are not changing the structure
of your original table in any way, so you can do no harm.
PivotTables allow you to pivot data using drag-and-drop techniques and receive results
immediately. PivotTables are interactive; once the table is complete, you very easily can
see how your information will be affected when you move (or pivot) your data. This will
become patently clear once you give PivotTables a try.
Even for experienced PivotTable developers, an element of trial and error is always
involved in producing desired results. You will find yourself pivoting your table a lot!
What Are PivotTables Good For?
PivotTables can produce summary information from a table of information. Imagine you
have a table of data that contains names, addresses, ages, occupations, phone numbers,
and Zip Codes. With a PivotTable, you very easily and quickly can find out:
If your data needs slicing, dicing, and reporting, PivotTables will be a critical part of your
toolkit.
Perhaps the biggest advantage to using PivotTables is the fact that you can generate and
extract meaningful information from a large table of data within a matter of minutes and
without using up a lot of computer memory. In many cases, you could get the same
results from a table of data by using Excel's built-in functions, but that would take more
time and use far more memory.
Another advantage to using PivotTables is that if you want some new information, you
can simply drag-and-drop (pivot). In addition, you can opt to have your information
update each time you open the workbook or click Refresh.
Microsoft introduced PivotCharts in Excel 2000. The table you create via the PivotTable
Wizard produces a PivotChart (or, more accurately, a PivotTable and PivotChart Report).
When you create a PivotTable, you also can create a PivotChart at the same time, with no
extra effort. PivotCharts enable you to create interactive charts that previously were
impossible without using either VBA or Excel Controls.
When you create a PivotTable, you must organize the dataset you're using in a table
and/or a list. As the PivotTable will base all its data on this table or list, it is vital that you
set up your tables and lists in a uniform way.
In this context, a table is no more than a list that has a title, has more than one column of
data, and has a different heading for each column. A list often is referred to in the context
of a table as well. The best practices that apply to setting up a list will help you greatly
when you need to apply a PivotTable to your data.
When you extract data via the use of lookup or database functions, you can be a little less
stringent in how you set up the table or list. This is because you can always compensate
with the aid of a function and probably still get your result. Nonetheless, it's still easiest
to set up the list or table as neatly as possible. Excel's built-in features assume a lot about
the layout and setup up of your data. Although they offer a degree of flexibility, more
often than not you will find it easier to adhere to the following guidelines when setting up
your table or list:
• Headings are required, as a PivotTable uses them for field names. Headings
should always appear in the row directly above the data. Also, never leave a blank
row between the data and the headings. Furthermore, make the headings distinct
in some way; for instance, boldface them.
• Leave at least three blank rows above the headings. You can use these for
formulas, critical data, etc. You can hide the rows if you want.
• If you have more than one list or table on the same worksheet, leave at least one
blank column between each list or table. This will help Excel recognize them as
separate entities. However, if the lists and tables are related to each other,
combine them into one large table.
• Avoid blank cells within your data. Instead of leaving blank cells for the same
data in a column, repeat the data as many times as needed.
• Sort your list or data, preferably by the leftmost column. This will make the data
easier to read and interpret.
Figure 4-1 shows a well-laid out table of data, and a PivotTable in progress. Note that
many of the same dates are repeated in the Date column. In front of this data is the
Layout step for the data showing the optional Page, Row, and Column fields, as well as
the mandatory Data field.
As noted earlier, to help users create PivotTables, Excel offers a PivotTable and
PivotChart Wizard. This Wizard guides you through the creation of a PivotTable using a
four-step process, in which you tell Excel the following:
• How the data is set up and whether to create an associated PivotChart (if
PivotCharts are available in that version of Excel)
• Where the data is stored-e.g., a range in the same workbook, a database, another
workbook, etc.
• Which column of data is going into which field: the optional Page, Row, and
Column fields, as well as the mandatory Data field
• Where to put your PivotTable (i.e., in a new worksheet or in an existing one)
You also can take many side steps along the way to manipulate the PivotTable, but most
users find it easier to do this after telling Excel where to put it.
Excel 2000 and later versions have a major advantage over Excel
97: they enable you to choose how to set up your data after the
Wizard is finished.
Now that you know more about PivotTables and what they do, it's time to explore some
handy techniques that can make this feature even more powerful.
Assuming you have a PivotTable in a workbook, all you need to do is select the entire
PivotTable, copy it, and on a clean sheet select Edit Paste Special... Values. Now
you can move this worksheet to another workbook or perhaps use it as is.
The one drawback to this method is that Excel does not paste the PivotTable's formats
along with the values. This can make the static copy harder to read and perhaps less
impressive. If you want to include the formatting as well, you can take a static picture (as
opposed to a static copy) of your PivotTable and paste this onto a clean worksheet. This
will give you a full-color, formatted snapshot of the original PivotTable to which you can
apply any type of formatting you want, without having to worry about the formatting
being lost when you refresh the original PivotTable. This is because the full-color,
formatted snapshot is not linked in any way to the original PivotTable.
To create a static picture, format the PivotTable the way you want it and then select any
cell within it. From the PivotTable toolbar, select PivotTable Select Entire Table.
With the entire PivotTable selected, hold down the Shift key and select Edit Copy
Picture. From the Copy Picture dialog box that pops up, make the selections shown in
Figure 4-2, then click OK.
You also can use this picture-taking method on a range of cells. You can follow the
preceding steps, or you can use the little-noticed Camera tool on your toolbar.
To use this latter method, select View Toolbars Customize.... From the
Customize dialog, click the Commands tab, from the Categories box, select Tools, and
from the Commands box on the righthand side scroll down until you see Camera. Left-
click and drag-and-drop this icon onto your toolbar where you want it to be displayed.
Select a range of cells, click the Camera icon, and then click anywhere on the
spreadsheet, and you will have a linked picture of the range you just took a picture of.
Whatever data or formatting you applied to the original range will automatically be
reflected in the picture of the range.
Assume you have a long list of names in column A, with cell A1 as your heading, and
you want to know how many items are on the list, as well as generate a list of unique
items. Select cell A1 (your heading) and then select Data PivotTable and PivotChart
Report (or Data PivotTable Report on Macs) to start the PivotTable Wizard.
Make sure that either Microsoft Excel List or Database is selected, or that you have
selected a single cell within your data. This will allow Excel to automatically detect the
underlying data it is to use next. If you're using a Windows PC, select PivotTable under
"What kind of report do you want to create?" (This question isn't asked on Macintoshes.)
Click the Next button. The PivotTable Wizard should automatically have picked up the
correct range for your data in column A and will highlight it in your sheet. If it is
highlighted, click the Next button. Otherwise, use your mouse to select the range. Click
the Layout button and drag to the Data area what will be your only field-you should see
your title as it appears in cell A1 floating about. Drag the field again, this time into the
Row area. Your screen should look something like Figure 4-4. Click OK.
At this stage, if you want you can double-click the Field button in
the Data area (this is labeled Count of Names in Figure 4-3) and
change the Summarize by: option to a function of your choice-e.g.,
Sum, Average, etc. Excel will by default use the COUNT function if
it's working with text and use the SUM function if it's working with
numbers.
What if you want to have a macro perform all those steps for you, creating a PivotTable
from any column you feed it? If you simply record a macro, you'll find it often works
only if your data has the same heading. To avoid this, you can create a simple macro
stored in your workbook or in your personal macro workbook (described in Tutorial 7)
that you can use to create a PivotTable on any list of items. This requires that you write
some generic VBA code and enter it into a standard module in your personal macro
workbook or in any other workbook.
To start, select Tools Macro Visual Basic Editor (Alt/Option-F11) and then select
Insert Module. Enter the following code:
Sub GetCount( )
Dim Pt As PivotTable
strField = Selection.Cells(1,1).Text
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, _
SourceData:="=Items").CreatePivotTable TableDestination:="", _
TableName:="ItemList"
Set Pt = ActiveSheet.PivotTables("ItemList")
ActiveSheet.PivotTableWizard TableDestination:=Cells(3, 1)
Pt.AddFields RowFields:=strField
Pt.PivotFields(strField).Orientation = xlDataField
End Sub
To return to Excel, close the Script window, or press Alt/ -Q, and save your workbook.
Before running this code, select the heading of your list and ensure that your list contains
no blank cells.
The code will automatically create a named range of your list, called Items. It will then
create the PivotTable based on this named range on a new worksheet.
The next time you have a long list of data, you can simply select its heading and run this
macro. All the PivotTable setup work will be done in the blink of an eye.
Although PivotTables are a great way to summarize data and extract meaningful
information, there is no built-in option to have the Grand Total float to the top for a quick
bird's-eye view.
Before we describe a very generic method to move the Grand Total to the top, we'll
explain how you can accomplish this with the GETPIVOTDATA function, which is designed
specifically to extract data from a PivotTable.
You can use the function like this:
=GETPIVOTDATA("Sum of Amount",$B$5)
or like this:
=GETPIVOTDATA("Amount",$B$5)
Either function will extract the data and will track the Grand Total as it moves up, down,
left, or right. We used the cell address $B$5, but as long as you use any cell within the
PivotTable, you always will pick up the total.
The first function uses the Sum of Amount field, while the second one uses the Amount
field. If your PivotTable has the Amount field in the Data area, you need to name the
field Amount. If, however, the Amount field is being used two or more times in the Data
area, you must specify the name you gave it, or the name you accepted by default (see
Figure 4-5).
Figure 4-5. The Amount field used twice and named Sum of Amount in one case and Number Sold in
the other
You can double-click these fields to change them. This issue can become confusing if
you are not up to speed with PivotTables. Luckily in Excel 2002 and later, the process is
much easier, as you can have a cell fill in the arguments and give the correct syntax by
using the mouse pointer. In any cell, type = (an equals sign) and then use your mouse
pointer to click in the cell currently housing the Grand Total. Excel will automatically fill
in the arguments for you.
Unfortunately, if you use the Function Wizard, or first type
=GETPIVOTDATA( ) and then click in the cell currently housing the
Grand Total, Excel makes a mess by trying to nest another
GETPIVOTDATA function within that cell.
Probably the easiest, if least sophisticated, way to extract the Grand Total is to use the
following function:
=MAX(PivGTCol)
where the column currently housing the Grand Total is named PivGTCol.
You also can use the LARGE and SMALL functions to extract from a PivotTable a host of
figures according to their size. The following formula, for instance, extracts the second
largest figure from a PivotTable:
=LARGE(PivGTCol,2)
You can add some extra rows immediately above the start of the PivotTable and place
these formulas there so that you can see this type of information instantly, without having
to scroll to the bottom of your PivotTable.
When creating a PivotTable in Excel, you have lots of options for your data source. By
far the easiest and most powerful approach is to use data that resides within the same
workbook. Unfortunately, for whatever reason, this is not always possible or feasible.
Perhaps the data that resides in another workbook is entered daily, for instance, and the
users entering the data should not see the PivotTable.
Using a dynamic named range will greatly decrease the refresh time needed for your
PivotTable to update. As you cannot reference a dynamic named range from another
workbook, this also means you prevented the PivotTable from referencing perhaps
thousands of blank rows and causing the file size to increase substantially. This way, you
can pull in data from another workbook, and then base your PivotTable on the data in the
same workbook rather than referencing it externally.
In the workbook that will contain your PivotTable, insert a new worksheet and call it
Data. Open the workbook containing the data to be referenced, and ensure that the
worksheet containing the data is the active sheet. In any spare cell on this worksheet,
enter this formula:
=IF(A1="","",A1)
Select cell A1. Then cut it, activate your original workbook, and paste cell A1 in cell A1
on the Data sheet. This will give you the reference to the other workbook. Copy this cell
across as many columns as there are headings in your data source. Then select Insert
Name Define, and in the Names in Workbook: field, type PivotData. In the Refers
to: box, type the following:
=OFFSET($A$1,0,0,COUNTA($A:$A),COUNTA($1:$1))
Click Add, then click OK. Next, to insert some code that will run each time the workbook
is opened, right-click the Excel icon (located at the top left corner of the screen) and enter
the following code:
With Worksheets("Data")
.Range("2:1000").Clear
.Range("1:1").AutoFill .Range("1:1000")
.Range("2:1000") = .Range("2:1000").Value
End With
End Sub
This shortcut isn't available on a Mac. You'll have to open the VBE
by pressing Option-F11, or by selecting Tools Macro Visual
Basic Editor. Then Ctrl-click This Workbook in the Projects
window.
The preceding code includes only 1,000 rows of data. This figure should always be
greater than the number of rows you believe you will need. In other words, if your table
in the other workbook contains 500 rows, add a few hundred more to accommodate any
growth in the original table.
Avoid using an extremely high row number (like 10,000, unless you
actually have that much data), as this will greatly impact how
quickly the code runs and the data updates.
Save the workbook, close it, and then reopen it, making certain that you enabled macros.
The code you added will fire automatically and will copy the formulas in row 1 on the
Data sheet, then automatically convert all but row 1 into values only. This will leave you
with a copy of your original data source, which will update each time you open the
workbook.
Now you can hide this sheet if you want by selecting Format Sheet Hide or by
using the method described in [Example #5].
Now, to base a PivotTable on this dynamic named range, select anywhere within the
PivotTable, then select the Wizard option from the PivotTable toolbar. Click the Back
button until you reach Step 1 of the Wizard. Select the first option, Microsoft Excel List
or Database, click Next, and in Step 2, type =PivotData (the name of the dynamic named
range). Then click Finish.
You will not experience the lag that often occurs when a PivotTable is referencing an
external data source because now the data itself is stored within the same workbook. As
an added bonus, because you can use a dynamic named range, the PivotTable is dynamic
without having to reference heaps of blank rows, and the file is kept to a manageable size.
Finance Functions
Introduction
The Present Value is the current value of an investment or a loan. For a savings
account, a customer could pledge to make a set amount of deposit on a bank account
every month. The initial value that the customer deposits or has in the account is the
Present Value. The sign of the variable, when passed to a function, depends on the
position of the customer. If the customer is making deposits, this value must be negative.
If the customer is receiving money (lottery installment, family inheritance, etc), this
value should be positive.
The Future Value is the value the loan or investment will have when the loan is paid off
or when the investment is over. For a car loan, a musical instrument loan, a financed
refrigerator, a boat, etc, this is usually 0 because the company that is lending the money
will not take that item back (they didn't give it to the customer in the first place, they only
lend him or her some money to buy the item). This means that at the end of the loan, the
item (such as a car, boat, guitar, etc) belongs to the customer and it is most likely still
worth something.
As described above and in reality, the Future Value is the amount the item would be
worth at the end. In most, if not all, loans, it would be 0. On the other hand, if a customer
is borrowing money to buy something like a car, a boat, a piano, etc, the salesperson
would ask if the customer wants to put a "down payment", which is an advance of
money. Then, the salesperson or loan officer can either use that down payment as the
Future Value parameter or simply subtract it from the Present Value and then apply the
calculation to the difference. Therefore, you can apply some type of down payment to
your functions as the Future Value.
The Number Of Periods is the number of payments that make up a full cycle of a loan or
an investment.
The Interest Rate is a fixed percent value applied during the life of the loan or the
investment. The rate does not change during the length of the Periods.
It is very important to understand how these two arguments are passed to a function. The
period could be the number of months of a year, which is 12; but it could be another
length. Suppose a customer is getting a car loan that would be financed in 5 years. This is
equivalent to 5 * 12 = 60 months. In the same way, a cash loan can stretch from 0 to 18
months, a carpenter truck loan can have a life financing of 40 months, and a
condominium can be financed for 15 years of 12 months plus an additional 8 months; this
is equivalent to (15 * 12) + 8 = 188 months. Here is the tricky part, especially as far as
Microsoft Excel deals with its finance functions. If you pass the number of Periods in
terms of years, such as 5 for a car loan that stretches over 5 years, then you can pass the
Rate as a percentage value, such as 8.75%. If you pass the number of Periods in terms of
months, for example you can pass it as 44 for a car that is financed in 3 years and 8
months, then you must communicate this to the Rate argument by dividing the Rate by
12. In other words, a Rate of 8.75% would be passed as 8.75%/12. If the Rate was typed
in a cell named B2 that displays 8.75%, you can pass it as B2/12.
For deposits made in a savings account, because their payments are made monthly, the
rate is divided by the number of Periods of a year, which is 12. If an investment has an
interest rate set at 14.50%, the Rate would be 14.50/12 = 1.208. Because the Rate is a
percentage value, its actual value must be divided by 100 before passing it to the
function. For a loan of 14.50% interest rate, this would be 14.50/12 = 1.208/100 = 0.012.
The Payment is the amount the customer will be paying. For a savings account where a
customer has pledged to pay a certain amount in order to save a set (goal) amount, this
would be the amount the customer would pay every month. If the customer is making
payments (car loan, mortgage, deposits to a savings account, etc), this value must be
negative. If the customer is receiving money (lottery installment or annuity, family
inheritance, etc), this value must be positive.
The Payment Type specifies whether the payment is made at the beginning or the end of
the period. For a monthly payment of an item financed like a car, a boat, a guitar, or a
house this could be the end of every month.
To calculate the future value of an investment, you can use the FV() function. The syntax
of this function is:
2. Save it as Business
3. Double-click Sheet1 to put its label into edit mode. Type Future Value and press
Enter
4. Click cell C8 and, on the main menu, click Insert -> Function...
5. In the Paste Function dialog box, in the Function Category list, click Financial. In
the Function Name list, double-click FV and move the FV window so you can see
the values on the worksheet
6. Click the box to the right of Rate and, on the worksheet, click cell C5 and type /12
7. In the FV window, click the box to the right of Nper and, on the worksheet, click
cell C7
8. In the FV window, click the box to the right of Pmt and type -
9. On the worksheet, click cell C6
10. In the FV window, click the box to the right of Pv and type -
11. On the worksheet, click cell C4
12. Since this is a loan, the payments are expected at the end of the month. Therefore,
in the FV window, click the box to the right of Type and type 0
13. Click OK
To calculate the number of periods of an investment or a loan, you can use the NPER()
function. Its syntax is:
Here is an example:
Investment or Loan Payment
The PMT() function is used to calculate the regular payment of loan or an investment. Its syntax is:
In the following example, a customer is applying for a car loan. The cost of the car will be entered in
cell C4. It will be financed at a rate entered in cell C6 for a period set in cell C7. The dealer estimates
that the car will have a value of $0.00 when it is paid off.
Practical Learning: Calculating the Monthly Payments of a Loan
1. Double-click Sheet3 to put it in edit mode. Type Payments Amount and press Enter
2. Complete the worksheet as follows
3. Click cell C8 and type =PMT(
4. Click cell C6 and type /12,
5. Click cell C7 and type ,-
6. Click cell C4 and type ,
7. Click cell C5
8. Type ,0) and, on the Formula Bar, click the Enter button
9. Suppose that, during the evaluation, a customer decides that she doesn't need a brand new car
anymore. Also, she thinks that a 5-year car loan is too long. Furthermore, she wants to make a
$4500.00 down payment to reduce the monthly payments. On the other side of the desk, the
salesperson who wants to make a juicy commission on this loan has decided to increase the
interest rate.
Change the new values of the worksheet as follows and see the result
The IPMT() function is used to calculate the amount paid as interest on a loan during a period of the
lifetime of a loan or an investment. It is important to understand what this function calculates.
Suppose a customer is applying for a car loan and the salesperson decides (or agrees with the
customer) that the loan will be spread over 5 years (5 years * 12 months each = 60 months). The
salesperson then applies a certain interest rate.
The IPMT() function can help you calculate the amount of interest that the lending institution would
earn during a certain period. In essence, you can use it to know how much money the company
would earn in the 3rd year, or in the 4th year, or in the 1st year. Based on this, this function has an
argument called Period, which specifies the year you want to find out the interest earned in.
The Rate argument is a fixed percent value applied during the life of the loan.
The PresentValue is the current value of the loan or investment. It could be the marked value of the
car, the current mortgage value of a house, or the cash amount that a bank is lending.
The FutureValue is the value the loan or investment will have when the loan is paid off.
The NPeriods is the number of periods that occur during the lifetime of the loan. For example, if a
car is financed in 5 years, this value would be (5 years * 12 months each =) 60 months. When passing
this argument, you must remember to pass the right amount.
The Period argument represents the payment period. For example, it could be 3 to represent the 3rd
year of a 5 year loan. In this case, the IPMT() function would calculate the interest earned in the 3rd
year only.
The PaymentType specifies whether the periodic (such as monthly) payment of the loan is made at
the beginning (1) or at the end (1) of the period.
The RATE() function is used to calculate the interest applied on a loan or an investment. Its syntax
is:
All of the arguments are the same as described for the other functions, except for the Guess. This
argument allows you to give some type of guess for a rate. This argument is not required. If you omit
it, its value is assumed to be 10.
IRR(Values, Guess)
The Values argument is a series (also called an array or a collection) of cash amounts that a customer
has made on an investment. For example, a customer could make monthly deposits in a savings or
credit union account. Another customer could be running a business and receiving different amounts
of money as the business is flowing (or losing money). The cash flows don't have to be the same at
different intervals but they should (or must) occur at regular intervals such as weekly (amount cut
from a paycheck), bi-weekly (401k directly cut from paycheck), monthly (regular investment), or
yearly (income).
The Values argument must be passed as a collection of values, such as a range of selected cells, and
not an amount. Otherwise you would receive an error.
The Rate parameter is the rate of discount during one period of the investment.
As the NPV() function doesn't take a fixed number of arguments, you can add a series of values as
Value1, Value2, etc. These are regularly made payments for each period involved. Because this
function uses a series of payments, any payment made in the past should have a positive value
(because it was made already). Any future payment should have a negative value (because it has not
been made yet).
The average person shies away from the financial functions in Excel because they think
they are only for the mathematical wizards. But, if you use the Insert Function button,
some of them aren t too hard to learn and can answer some questions we all have.
Scenario
You want to buy a new car and the car dealers all offer different interest rates and
payment plans. They throw a lot of numbers and plans at you, but usually all you want to
know is how much of a downpayment do I need to make so I can afford the monthly
payments?
Well, Excel can figure this out for you pretty easily, using the PMT function.
Let s say you know that the car you want costs $25,000 and you know you can only
afford $450 a month for car payments. You have $6,000 in your savings account, but you
don t necessarily want to use it all for a downpayment. So, how much do you really
have to put down on this car in order to get the payments you can afford?
First, talk to your lending agency and find out how many years you have to pay and what
the interest rate is that they are offering. Then enter this information in a new blank
worksheet.
A B
1 Car Loan
2 Number of payback years 4
3 Total Number of payments =B2*12
4 Loan Amount =25000-B6
5 Interest Rate for Loan 4.9%
6 DownPayment 6000
7 MONTHLY PAYMENT
This shows, in cell B4, you are borrowing $19,000 ($25,000 minus the downpayment of
$6000 which you put in B6), over four years (B2), totaling 48 payments (B3, which
multiplies the number of years by 12 months), at a yearly interest rate of 4.9%. Notice
that I put formulas in both B3 and B4, so you can change the number of payback years
and the downpayment amount and everything else will be adjusted automatically.
Now let s figure out what the monthly payment would be with these figures.
4. Now, all you have to do is fill in the boxes and Excel will give you
your answer:
Click in cell B6 and change the downpayment to $3000. And look how close we still are!
$505.65. and only using half of our savings for the downpayment!
Can we get it even lower? Sure! Click in cell B7 where your PMT formula is and look in
your formula bar at the top of your screen and see the formula is
=PMT(B5/12,B3,B4,0,0). Change that last zero to a 1 (assuming your lending agency
allows for paying at the beginning of the month). That saved you another two bucks and
now your payment is $503.59.
Maybe your lending agency allows you to pay over 5 years instead of 4? If so, change the
4 in cell B2 to a 5 and notice your number of payments in cell B3 adjusts to 60 and your
monthly payment drops to $412.48. WOW! Maybe we can make even less of a
downpayment!
Click in cell B7 and change that downpayment amount to $1000 and see that your
monthly payment is $449.97 and right in line with what you want to pay. And, you still
have FIVE THOUSAND BUCKS left in your savings account!
So, you can see that Excel can be a handy tool when you are trying to figure out stuff like
this. And, you can go back to that car dealer armed with all you need to know to bargain
with him/her.
And, if you want to know if you can retire early, try Excel s Financial Function named
FV and see if you can figure out how to determine what that savings plan you have
will be worth in 25 years.
Remember, Excel doesn t require that you are a mathematician. Excel does the work for
you!
Linda Johnson is a college instructor of all of the Microsoft Office programs and also
offers private training to companies in the Philadelphia area. Companies outside that area
can also buy corporate licenses for distributing her ebooks and CD or send their
employees to her online classes. See more info about Linda on the TechTrax consultants
page or go directly to her services page to learn more about her online classes, ebooks
and CD: http://www.personal-computer-tutor.com/services.htm.
DB
Returns the depreciation of an investment using the fixed-declining
balance method for the specified period. The 'life' and 'period'
arguments must use the same units of measure.
Syntax
DB(cost,salvage,life,period,{months})
Arguments
Example
DB(10000,1000,5,1) is $3,690.
DDB
Returns the depreciation of an investment using the variable declining
balance method for the specified period. The life and period arguments
must use the same units of measure.
Syntax
DB(cost,salvage,life,period,{factor})
Arguments
Example
DDB(10000,1000,5,1,3) is $6,000.
FV
Returns the future value of an investment based on constant periodic
payments and a constant interest rate.
Make sure that the rate corresponds to the number of payment periods. For
a monthly payment period remember to divide an annual interest rate by
12 (months) to get a monthly interest rate. Enter cash paid out as negative
values, and any cash received as positive values.
Syntax
FV(rate,periods,payment,{pv},{atEnd})
Arguments
Example
FV(.10/12,5*12,-100) = $7,743.71.
You save $7,743.71 after 5 years depositing $100 a month with no initial
deposit and a 10% interest rate.
NPER
Returns the number of periods for an investment with a constant cash flow
and interest rate given a present and future value.
Make sure that the rate corresponds to the number of payment periods. For
a monthly payment period remember to divide an annual interest rate by
12 (months) to get a monthly interest rate. Enter cash paid out as negative
values, and any cash received as positive values.
Syntax
Arguments
Example
NPER(.08/12,-100,2000) = 21.54.
PMT
Returns the payment amount needed to finance an investment.
Make sure that the rate corresponds to the number of payment periods. For
a monthly payment period remember to divide an annual interest rate by
12 (months) to get a monthly interest rate. Enter cash paid out as negative
values, and any cash received as positive values.
Syntax
Arguments
Example
PMT(.08/12,12*3,10000) = -$313.36.
$10,000 borrowed at 8% annual interest requires a monthly payment of
$313.36 to pay off the loan in 3 years.
PV
Returns the present value of an investment based on constant periodic
payments and a constant interest rate.
Make sure that the rate corresponds to the number of payment periods. For
a monthly payment period remember to divide an annual interest rate by
12 (months) to get a monthly interest rate. Enter cash paid out as negative
values, and any cash received as positive values.
Syntax
Arguments
Example
PV(.10/12,5*12,-100,10000) is -$1371.35.
PV(.08/12,3*12,-300) is $9,573.54.
The financial function we're going to explore will calculate the monthly payment
amounts on a loan. The function we're going to use is PMT( ).
The PMT( ) function expects certain values in between those two brackets. The values
are known as arguments. The arguments that the PMT( ) function expects are these:
The last two, fv and type, are optional. If all this sounds very confusing, then don't worry:
we'll clear it up with an example.
The example is this: You want to borrow ten thousand pounds from your friendly banker.
You also want to pay it back over 5 years. What you need to know is - how much will
this loan cost me every month?
We'll work it out with the PMT( ) function. First, create a new spreadsheet like the one
below:
The figure in cell B1 is the amount we want to borrow - ten thousand pounds. Our
financial function PMT( ) will go under Monthly Amount, in cell D4.
Before we can enter our function, we need to work out the Interest Rate, the Number of
Payments, and the Present value. These are the arguments for our function. Let's start
with the Interest Rate, the first of our arguments (rate).
The bank tells us that the interest rate is 12 percent. This is for the entire year. As we
want to know how much to pay back each month, we need to divide this figure by 12 (12
months in a year; divide this into 12 percent). Of course, this is a simple division: 12
divided by 12 is 1. But we'll let Excel work it out. So do the following:
= 12% / 12
The next thing we need to work out is how many payments there are in total. We are
paying back the loan every month for 5 years. As there are 12 months in a year, the
formula is just 12 multiplied by 5. So do this:
= 12 * 5
OK, we have now worked out the second argument for our PMT( ) function - the nper
bit. We can now move on to the pv part of the argument, or Present Value. The Present
Value is sometimes known as the Principal. It is what the loan is worth now, and not say
5 years into the future. In other words, it's ten thousand pounds for us. So for the Present
Value column in your spreadsheet, do this:
= B1
Time now to enter our PMT( ) function in cell D4. So, do the following:
• Click inside cell D4
• Click inside the formula bar
• Enter the following function:
Excel should now have entered the monthly payments in cell D4. It is usually in red, and
with a minus sign at the start (minus because it's what you owe to the bank). The answer
you should have in D4 is -£222.44.
So we have to pay back to the bank every month two hundred and twenty two pounds
forty four pence.
The final column is "Total Paid Back". To work out that answer you need to multiply the
monthly payments by the number of payments. Which should cause you no problems at
all. When you're done, the final spreadsheet looks like this:
We can make only a few slight changes to the spreadsheet to answer these questions.
Insert two more rows into your spreadsheet, and add two labels. Your spreadsheet sheet
match the one below:
= 12 % / 12
If we put the percentage figure in a cell of its own, we could then reference that cell in
our formula. We could just put this:
= B3 / 12
Then we could vary the interest rate by changing the number in cell B3. To clear any
confusion, do the following:
You can now change the formula for your interest rate. So click inside the cell where you
interest rate is, probably cell A6. Click inside the formula bar. Change the formula from
this:
= 12 % / 12
to this:
= B3 / 12
When you press the Return key on your keyboard, all of your monthly payment terms
should stay the same. The difference is that you can now alter the interest rate from cell
B3. Test it out. Change the interest to 10 percent and see what happens to your Monthly
Amount figure.
Exercise
The Number of Payments formula currently reads = 12 * 5. Change this formula so that
number of years is coming from cell B2.
When you're finished, you final spreadsheet will look like this one:
Play about with the figures in cells B1 to B3 and watch the D6 and E6 figures change.
What about a ten year loan with interest of 15 percent?
PMT extra
You can use the PMT( ) function to work out your savings. You might want to know how
much you'll have to put away in the bank if you want to save 2 thousand pounds in one
year. Remember the full PMT( ) function? It was this:
To work out how much you'll have to save each month, you need that fv part. The fv
stands for Future Value. You would then use the function like this (assume that the
interest rate is a massive 10 percent):
In the next part, we'll take a look at how to use IF Statements in your spreadsheets. This
is known as Conditional Logic.
Conditional logic(IF) is used quite frequently in modern spreadsheets. But let's start by
asking What is Conditional Logic?
Conditional Logic
For our purposes, conditional logic is two words - "IF" and "Then". You use conditional
logic all the time in your daily life, without realising it. You might say to yourself, "IF I
eat this delicious cream cake THEN my diet will be ruined." You're using conditional
logic to make a decision: IF I do this THEN that will happen. Some more examples:
Those are all example of conditional logic. Excel also uses the IF word for conditional
logic. You can test what is in a cell, and say what should happen if it is one value rather
than another. For example, suppose cell A1 has the number 6 in it. In cell A2, you can
enter an IF function to test whether cell A1 is above 5 or below 5. IF it is above 5 THEN
one thing happens; IF it is below 5 THEN another thing happens.
So the IF function takes three arguments: logical test, value if true, value if false. Let's
break those three arguments down a little more:
Logical Test:
This is what you want to test for. In our example, we wanted to test whether cell
A1 is greater than or less than 5. Excel uses this symbol > for greater than and this
symbol < for less than. So for the first argument, we would put A1 > 5
Value If True:
This is the THEN part of the IF statement. Excel needs to know what you want to
happen IF your condition is met. You can put in text surrounded by quotes, or
another formula.
Value If False:
You also need to say what should happen IF your condition is not met.
Let's clarify all this with a spreadsheet example. So, start a new spreadsheet and do the
following:
It's important you get all the syntax right in your IF function. In other words, don't forget
the commas, and the double quote marks around text.
But click inside cell A1 and change the number 6 to the number 4. Then press the return
key on your keyboard. Excel should put Less than Five in cell B1. Now put the number 5
in cell A1 and see what happens.
Nothing happened, right? That's because the IF function is very precise. You didn't tell
Excel what to do if the number equalled 5.
To get round this, we can use the Greater Than ( > ) symbol and the Equal symbol
together. Like this:
A1 >= 5
That says "A1 greater than or equal to 5". When we amend our function, it looks like this:
=IF(A1 >= 5, "Greater than or Equal to Five", "Less than Five")
You can also test to see if something is Less Than ( < ) or Equal to. You could use this
for the formula:
You can even test for Not Equal To. Just join the Less Than (<) symbol to the Greater
Than (<) symbol. Like this:
So to sum up: after typing IF you tell Excel what you want to test for. Then you say what
should happen if the condition is true. Then you say what should happen if the condition
is false.
If statements in spreadsheets can be very long and complicated. Consider this problem.
You have a spreadsheet of student exam marks. Suppose you want to add the grades as
well. If the student scored above 80 it's an A; if the student scored between 60 and 79, it's
a B; if the student scored between 45 and 59, it's a C; if the student scored between 30
and 44, it's a D; and if the student scored less than 30, it's Fail. The question is, what does
your IF statement look like?
=IF(B2>=80, "A", IF(B2>=60, "B", IF(B2>=45, "C", IF(B2 >=30, "D", "Fail"))))
What the IF statement is doing is nesting another IF statement on the False condition. So
it says, "If B2 is greater than or equal to 80 THEN put an A in cell B15; if it's not,
execute another IF statement."
But don't worry if that long IF statement is making your brain hurt - it is quite
complicated!
However, we'll use that long IF statement to explore Conditional Formatting. You'll be
glad to know that there is a spreadsheet already prepared for you, for this lesson. So right
click the link below and save the spreadsheet to your own computer.
It looks a bit hard to follow at the moment. It's difficult to know what the data is
supposed to represent. Conditional formatting will help to clarify things.
Conditional Formatting
We can use Conditional logic, however, to format the spreadsheet. What we'll do is to
colour those Overall Averages depending on the grade. One colour will represent a high
grade, a second colour will mean an average grade, and a third colour will mean a low
grade. So let's get started.
• With your Spreadsheet open, Highlight the cells with Overall Averages in them
(From B12 to I12)
• With the cells highlighted, click on Format form the menu bar
• From the drop down menu, click on Conditional Formatting
• A dialogue box appears, the one below:
At the top, it says Condition 1, and there are 4 text boxes to fill in. The first two "Cell
Value Is" and "Between" will suit our purposes, so:
You can now set the colour to use for this condition. So click the Format button. Another
dialogue box appears. From the Patterns Tab Strip, select a colour or pattern to use. Then
click the OK button at the bottom. Your dialogue box will look something like the one
below:
You can now add a second condition. To do that, click the Add button at the bottom of
the dialogue box. Condition 2 will appear. Repeat the above process: enter some numbers
for the middle set of grade (65 to 79, perhaps), and select a different colour by clicking
the Format button. Add a third condition for the lowest grades. When you're done, click
the OK button. Your Overall Averages should change colour depending on what grade
the student got. (Unfortunately, Excel only allows you a maximum of 3 conditions.)
Your spreadsheet might look something like the one in the next image:
The conditional formatting allows you to see at a glance which students are doing well,
and which are doing badly. Poor Mark!
Exercise
Format the Student Grades so that your spreadsheet looks like the one below (you can use
different colours, if you like).
In the spreadsheet above, you can now see more easily who's doing well and who isn't. In
the next section, we'll take a look at CountIF. Again, we'll use the student spreadsheet.
The next Conditional function we're going to use is CountIF. This one is fairly
straightforward. It looks at a range of cells and tells you how many of them meet the
criteria that you set. Once again, we'll use the student exam marks spreadsheet.
Open up the Spreadsheet you used for the last section. (If you haven't yet downloaded the
spreadsheet, click here: Download the spreadsheet.)
Because the exam spreadsheet might be a little full, we'll start on a new sheet. We'll copy
and paste the student data onto sheet 2. To do that, follow these steps:
• With the data highlighted, click on Edit from the menu bar
• From the drop down list, click on Copy. The marching ants surround your
highlighted data
• Look at the bottom of the spreadsheet and locate Sheet2, as in the next image:
CountIF
The CountIf function only calculates things when a certain condition is met. For example,
only count the students whose grades are above B.
COUNTIF(range, criteria)
In other words, it takes two arguments. The first argument is range, and this means the
range of cells you want to count. The criteria is what you want excel to look for when it is
counting. Let's see it in action.
The formula says, look in cells B2 to I2. Then check for a score of greater than or equal
to 70. If you find this score, keep a Count.
So 4 students achieved a mark of 70 or above for Maths. To do the rest of the scores, you
can use AutoFill. When you have finished, it should look like this one below:
CountIF is a very useful function for simple data analysis. In the next part, we'll take a
look at two more useful functions: AND and SUMIF.
Two more useful Conditional Functions are AND( ) and SUMIF( ). We'll stay with the
students exam results to examine these two functions. If you haven't yet downloaded the
spreadsheet we're using for these lessons, click below. (If you've been following along,
you can use this new spreadsheet: it has the CountIF already done!)
Here's the scenario. The government have decided to take a closer look at school
averages. If 4 or more students in a subject get a score of 70 or above, then the school
gets a cash bonus for that subject. There are 8 subjects, so 8 cash bonuses are up for
grabs.
First, we'll use the AND function to work out if 4 or more students have scores of 70 or
above.
The AND( ) function checks a list of arguments and determines whether they are true or
false. If all the arguments are true then the function gives you an answer of TRUE. If one
or more of the arguments are false, then the function gives you an answer of FALSE.
To give you an easy example. You can check whether two plus two does indeed equal 4.
Click inside an empty cell of your spreadsheet, then click inside the formula bar. Enter
this:
=AND(2 + 2 = 4)
When you press the Return key, Excel gives you the answer TRUE. Now change it to 2 +
3 = 4 and see what happens.
So Excel checked the argument to see whether it was true or false. That's all it will check
for, an either or answer. You can have up to 30 arguments between the AND brackets.
You could have this, for example:
= AND(2 + 2 = 4, 1 + 2 = 4)
There's two arguments to check there. Excel will check the first one and return an answer
of TRUE. When it checks the second one it will return an answer of False. The answer to
the whole function will then be FALSE. (It's false because all conditions have to be true
before the overall answer is TRUE.)
Our AND function is going to be quite simple. We're going to check the B column, the
Number of students who have Below Average scores.
= AND(B15 >= 4)
All we're saying in our function is "IF the cell B15 is greater than or equal to 4 THEN put
True in cell C15, else put False". Remember: the government pays out if 4 or more
students get above a score of 70 for a lesson
Now that we have some True/False values for our C column, we can check all these
True/False values. We want to add up all the cash values associated with our TRUE cells.
However, we haven't got any cash values yet, so let's do that now. Enter the same cash
values as in the image below:
The values are just potential values. A school only gets them if 4 or more students gain a
score of 70 or above in that subject. So there's a potential ten thousand for Maths, five
thousand for English, 8 thousand for Science, etc.
OK, we have 2 cells with TRUE in them. There is a different cash value associated with
each subject. We have a TRUE for English, so the school will receive 5 thousand pounds
for this. The school can expect 10, 000 for Maths. But we need a way to add all the cash
values associated with the TRUE values. We can use SUMIF for this.
SumIF
SUMIF is a little bit more complicated than AND, but not much more. This function adds
up things depending on the criteria you give it. (Add up the cost of all apples, for
example.) The function expects certain arguments. These are:
The first argument, range, is the cell or cells you want to check. For us, this would be the
TRUE and FALSE values in the D column. The second argument, criteria, is what you
want to check for. In our case this is the value TRUE. The third argument, sum_range,
are the cells to add up. The figures we want to add up are all in the E column.
If everything went well, then you should have a figure of 11 thousand for your SUMIF
function. Your spreadsheet might look like the one below:
So our SUMIF function said "Check the cells C15 to C22. If a cell has TRUE in it, make
a note of the ammount in the E cell next to it. When you've finished, add them all up."
The SUMIF might be a bit tricky to master, but it can come in quite handy, and it's worth
making the effort to understand exactly how it works.
In any case, that concludes are little journey into conditional logic. Hope you're not too
disappointed to be leaving the subject behind!
In the next section of the Excel course, we'll take a look at Tables, Scenarios and Goal
Seek.
In Excel, a data Table is a way to see how altering the values in a formula effects the
result. Excel will work out the new results for you, based on the new values you give it.
Take the following as an example:
You decided to take out a loan of ten thousand pounds. You want to pay back the loan
over 5 years. The first bank you try sets a interest rate of 9 percent per year. You use the
PMT formula to work out how much you have to pay back every month:
Another way to work out the monthly payments for the new interest rates is to use a
Table. Excel will then use the PMT function, and the new interest rates, and work out the
answers for you. We'll see how to do that now.
Excel Tables
So the Rate (interest rate) is 9 percent, the Months value is 60, and the Loan is 10, 000
pounds.
Just in case you're unsure about that PMT Function, here's what it's doing. The first
argument for PMT is the rate, meaning the interest rate. The cell B3 is where we had our
interest rate of 9 percent. We need to divide that by 12 (the number of months in a year),
otherwise the bank will be charging us 9 percent a month! The second argument, where
we have B4, is nper. This is just the total number of months in our loan. The third
argument is how much we want to borrow. We have this amount in cell B5. It is a minus
figure because it's a debt.
Now that we have a function in place, we can construct our Excel Table. First, we need to
tell Excel about those other interest rates. It will use these to work out the new monthly
payments. Remember, Excel is recalculating the PMT function. So it needs some new
values to calculate with.
We have deliberately put the PMT function in cell D2. This is one Row up, and one
Column to the right of our first new interest rate of 8%. The new monthly payments are
going to go in cells D3 to D5. Excel needs you to set the table out this way.
So that Excel can work out the new totals, you have to highlight both the new values and
the Function.
As you can see, the cells C2 to D5 are highlighted. This includes our new interest rate
values, and our function in cell D2. We can now create a Table. So do this:
The Input Cell is the cell that you want Excel to substitute. The thing we want Excel to
substitute is the interest rate. We had our interest rate in cell B3. So we use this as the
Input Cell.
We wanted Excel to fill downwards, down a column. So we need the second text box on
the dialogue box "Column input cell". If we were filling across in rows, we would use the
"Row input cell" text box.
So at an interest rate of 9 percent, we would be paying back just over two hundred and
seven pounds. Excel has worked out that an interest rate of 8 percent will lower the
monthly payments to just over two hundred and two pounds. At a 6 percent interest rate,
the payments will be just over one hundred and ninety three pounds.
If you click inside cells D3, D4 and D5, then look at the formula bar, you will see this:
{=TABLE(,B3)}
That's Excel's way of telling you that a Table has been created.
We'll do one more Table. This time we'll use a more simple formula than PMT, and we'll
use Rows instead of Columns. We'll do that in the next part.
In the previous part, we saw how to use an Excel Table to work out interest rates. The
Table was used to fill out several values at once. We'll now see how to use a Table to
examine profir margins. Here's the scenario:
You take 250 items to a Car Boot sale. Your Unique Selling point is this: All items only a
pound each! Except you feel that one pound might be a bit expensive, especially for the
goods you're selling! What you want to know is how much profit will you make if you
reduce your prices to ninety pence each, how much if you reduce to 80 pence each, and
how much if you reduce to 70 pence each. Assume that everything gets sold.
To start creating your Table, construct a spreadsheet like the one below. Make sure that
you start on a new sheet.
Number is the number of items we're taking to the Car Boot sale. Price will be used in
our formula. Reductions is the amount we want to reduce by. Sales is the amount of profit
we expect to make. Our formula will go in cell B4. So click inside cell B4 and enter the
formula:
= B1 * B2
The answer is, of course, 250. But the answer is in cell B4 for a reason. This is because
when you want Excel to recalculate a Table in Rows, the formula must be inserted one
Column to the Left of your first new value, and then one Row down. Our first new value
is going in cell C3. So one column to the left takes us to the B column. One row down is
Row 4. So the formula goes in cell B4.
Next, click inside cell B3 and highlight to cell E4. Your spreadsheet should now look like
the one below:
Excel is going to use your formula in cell B4. It will then look at the new values on Row
3 (not counting the zero), and then insert the new totals starting in cell C4.
So with the data highlighted, click on Data from the menu bar
From the drop down list, click on Tables
The Table dialogue box appears
We want Excel to fill our new values in Row 4, so we need the Row input cell. But what
is the Input Cell this time?
Ask yourself what you are trying to work out, and what you want Excel to recalculate.
You want to work out the new prices. So you need the old price. The old price of each
item was one pound, and you used this in the formula.
• So on the Table dialogue box, click inside the "Row input cell" text box
• Enter your cell reference
• Click OK when you are done
• If you got it right, your spreadsheet will look like the one below:
So, if you don't reduce your prices, you will make two hundred and fifty pounds. If you
reduce the price of each item to seventy pence, you will make one hundred and seventy
five pounds.
Tables are a useful tool when you want to analyze values that can change. Before moving
on, try this exercise.
Exercise
Amend the table above. This time, instead of reducing your prices, you are going to
increase the price to £1.25 per item, and increase the number of items you sell. You
currently sell 250 items. Work out the new profits if you sell 300 items, 350 items, and
400 items.
In the next part, we'll move on to Scenarios.
Scenarios are similar to Tables, in that you are asking "What if"? "What if I change this
value, or that amount? What will the spreadsheet look like then?" The difference is that
you can create a number of different scenarios and save them.
You've worked out the family budget, and find you have barely enough left for a night
out. The question is, what can you cut back on to give yourself more spending money?
We'll create a spreadsheet to tackle that problem, and you'll see how scenarios work. To
get started, there's a new spreadsheet for you to download:
When you open up the spreadsheet, you'll see there is only 46 pounds left at the end of
every month. And the cost of the car hasn't even been included yet! Clearly, some
cutbacks have to be made.
With a scenario, we can switch between our different budgets and see which one we like
best. The best way to see how a scenario works is to construct one yourself.
Scenarios
• Click inside the Scenario Name text box and type Original Budget
You now need to tell Excel which cells will be changing. Although nothing will be
changing in this scenario (because it's our original), we still need to specify which cells
will be changing. We want to reduce the Food bill, the Clothes Bill, and the Phone bill.
We now need to create another Scenario, so that we can switch between the original
budget and the new one. So click the Add button to add a new scenario.
• When you get the Add Scenario dialogue box back up again, click inside the
Scenario Name text box and type Budget Two.
• The Changing cells text box should read B7:B9. These are the cells we want to
change, so leave them alone
• Click the OK button at the bottom of the Add Scenario dialogue box
• You will be taken to the Scenario Values dialogue box. It looks like the one
below:
The values in the Text Boxes are the ones from cells B7, B8, and B9. Click inside each
text box and type in a different value. The 280 spent on food can be changed to
something like 180. Take 50 off the clothes bill. And take 20 off the phone bill. Your
dialogue box will then look like this one:
Click the OK button when you're done. You'll be taken back to the Scenario Manager.
And this is where the fun starts.
To view a scenario, click on one from the list. Then click the Show button. In the image
below, Budget Two has been selected:
After you click the Show button, have a look at your spreadsheet. The figures should
have changed. Select Original Budget from the list, then click the Show button. Your
spreadsheet should show the original figures.
Click the Close button on the dialogue box when you're done. To view your two
scenarios again, just click on Tools > Scenarios. This will bring up the Scenario
Manager again.
So a Scenario offers you different ways to view a set of figures, and allows you to switch
between them quite easily.
Scenario Reports
Another thing you can do with a scenario is produce a report. This is quite easy. To
produce a report of your scenarios, do the following:
All right, it's not terribly easy to read, but it looks pretty! Perhaps it will be enough to
convince our family to change their ways. Unlikely, but a nice diagram never hurts!
In the next part, we'll take a look at Goal Seek, what it is and how to use it.
We're not going go too deeply into Goal Seek, because it can get quite complicated. We'll
stick with a basic outline, and an example, of just what it is.
Goal Seek
Goal Seek is used when you know what answer you want, but don't know the exact figure
to input for that answer. For example, you're quite certain that 8 multiplied by something
equals 56. You just not sure what that missing number is. Is it 8 multiplied by 6? Or Is it
8 multiplied by 7? Goal Seek will tell you the answer.
We'll test that example out right now. So start a new spreadsheet, and create one the same
as in the image below:
Before you can use Goal Seek, Excel needs certain things from you. First it needs some
sort of formula to work with. In the image above we have the simple formula =B1 * B2.
We've put this in cell B3. But the answer is wrong for us. We had a Goal of 56 (8 times
something). We want to know which number you have to multiply 8 by in order to get the
answer 56. We tried 8 times 6, and that gave the answer of 48. So we have to try again.
Instead of us puzzling the answer out, we can let Goal Seek handle it. So do the
following:
The dialogue box needs a little explaining. "Set cell" is the answer you're looking for, this
is the Goal. Set cell needs a formula or function to work with. Our formula is in cell B3,
so if your "Set cell" text box does not say B3, click inside it and type B3.
"To Value" is the actual answer you're looking for. With "Set cell", you're just telling
Excel where the formula is. With "To Value" you have to tell Excel what answer you're
looking for. We wanted an answer of 56 for our formula. So click inside the "To Value"
text box and type 56.
"By Changing Cell" is the missing bit. This is the part of the formula that needs to change
in order to get the answer you want. In our formula we have an 8 and a 6. Clearly, the 6 is
the number that has to go. So the cell that needs to change is B2. So go ahead and enter
B2 in the "By Changing Cell" text box. Your dialogue box should now look like this:
Click OK when your dialogue box looks like the one above. Excel will then Set the cell
B3 to the Value of 56, and change the figure in cell B2. You'll also get a dialogue box
like the one below:
Click OK on the dialogue box. Your new spreadsheet will look like this one:
So Goal Seek has given us the answer we wanted: it is 7 that when times by 8 equals 56.
We'll work it out together using Goal Seek. And then you can have a try yourself with an
exercise. First, here's a new spreadsheet for you to download:
When you open the spreadsheet, you'll notice that the Current Sales Figures and the
Future Sales Figures are exactly the same. The formula in Cells B4 and E4 is = B2 * B3
We can use Goal Seek to solve our problem. What we want to know is, What should be
the new Price Per Item in order to generate Profits of 35 thousand?
This time, our formula is in cell E4. So we want to Set the cell to the cell that has our
formula. So type E4 into the "Set cell" text box.
The "To Value" text box will hold our new Profits. The Goal we are aiming for is 35
thousand. So type in 35000 in the "To value" text box.
The cell we want to change is the Price Per item figure. So in the "By changing cell" text
box, type in E3.
Click OK when you're done. Excel will give you this dialogue box:
The dialogue box is telling you that Goal Seek has found a solution. Click OK. Your
spreadsheet will already have changed. The new Future Sales Figures will be displayed.
Your spreadsheet should look something like the one below:
Goal Seek has given us the answer of 35 pounds. So the cost of each item has to increase
by 10 pounds if we want a profit of 35 thousand.
Exercise
You've had a board meeting. It has been decided that the Price Per Item will remain the
same - 25 pounds. But you still want to generate Profits of 35 thousand. Use Goal seek to
work out how many Items will now have to be sold in order to reach your target.
And that's it for this section. In the next section, we'll take a look at Absolutes versus
Relative cell referencing, Named Ranges and Pivot Tables. There's a lot to get through!
There are two important spreadsheet concepts we haven't yet explored: absolute cell
references, and relative cell references. We'll explore these two ideas now. First, absolute
cell references.
But suppose we wanted to copy the formula in cell B2 to cell B3. Let's try it and see what
happens.
Excel has done something rather odd. It has given us the answer 25! The sum 20 + 25
clearly does not equal 25, so what's going on?
Well, look inside the formula bar. The formula is now reading = A2 + A3. Yet that was
not the formula we pasted from cell B2. We copied and pasted the formula = A1 + A2.
So why did Excel copy and paste the wrong formula?
The answer is that we used a Relative cell reference for B2. We have been using Relative
cell references throughout this book. This is Excel's default, and it works like this when
you copy a formula:
The formula is = A1 + A2. The answer is in cell B2. When copying the formula to cell
B3 Excel will note that the cells for the formula start UP one Row, and LEFT one
column. When you paste the formula somewhere else, Excel will not paste the formula,
but paste this UP one then Left one. So starting at Cell B3, which is where we're pasting
to, go UP one Row. This takes you to row 2. Then go one column Left. This takes you to
Column A. So the start for the new formula is cell A2. Your formula will now read = A2
+ A3. As there is nothing in cell A3, the formula is really = 25 + 0. Which gives the
answer 25.
If you want to keep a reference to the original cells, A1 and A2, you need to use Absolute
cell references. Absolute cell referencing is done with dollar signs.
= $A$1 + $A$2
Then copy and paste the new formula to cell B3. You should now get the answer you
were looking for: 45. Your spreadsheet will look like the one below:
To recap, then:
• When you want to copy and paste formulas, use Absolute cell references
• To use Absolute referencing, place a dollar sign before the Column letter and a
dollar sign before the Row number (You can mix absolute and relative cell
references, but we won't go into that.)
In the next part of this section, we'll take a look at Named Ranges.
Instead of using something like = SUM(A2:A5) to add up a column of numbers, you can
replace the A2:A5 part of the function with a more descriptive name. This is known as a
Named Range. Examine the spreadsheet below:
In the Results Row, cell B5 is a result of adding up cells B2 to B4. The formula used is
just this:
=Sum(B2:B4)
Now examine the same spreadsheet, but with a Named Range used:
This time, cell B5 doesn't have in it the formula = Sum(B2:B4). As you can see, it has
=SUM(Monthly_Totals). This is the label from B1. We have created a Named Range.
The formula in cell B5 is now more descriptive. We can tell at a glance what it is we're
adding up. Excel has replaced the B2:B4 part with the name we gave it. Behind the
scenes, though, we're still adding up the numbers in cells B2 to B4. Excel has just hidden
the cell references behind our descriptive name.
Start a new spreadsheet, and enter the same data as in the image below:
Make sure you have the same formula in cell B5 =Sum(B2:B4). We're going to create a
Named Range, and then pop it in cell B5. To create a Named Range then, do the
following:
• Highlight the B column, from B2 to B4 (Don't include the formula when you're
highlighting. Just highlight the same cells as the ones in the function)
• From the menu bar, click on Insert
• From the drop-down menu select Name
• A sub menu appears like the one below:
There's a two-step process involved with setting up a Named Range. The fist thing to do
is Define the name. You then Apply the name to your formula.
You are returned to your spreadsheet. Nothing will happen. This is because we have
haven't done step two of the two-step process - Applying the name.
• Click inside the cell where your formula is, B5 in our case
• Click on Insert from the menu bar
• From the drop down menu, select Name
• From the sub menu that appears, click on Apply
• A dialogue box will appear showing a list of all the Names you have set up
You'll have only one Name set up , so there's not much to do except click the OK button.
When you click OK, Excel should adapt your formula in cell B5. If you've done it right,
your spreadsheet should look like the one below:
As you can see, the cell B5 now reads =SUM(Monthly_Totals). Excel has hidden the cell
references behind the Name we defined.
If you didn't get the Name, but instead got the error message below, then there are a
couple of things you can do:
Before you click Insert > Name > Define, make sure you highlight only the same cells
as the ones in your formula. Make sure that there is a formula in the cell B5, and that it
says = SUM(B2:B4)
We can enter another Named Range for our Monthly Tax column, column C. Here's a
break down of the Two-Step process involved with setting up a Named Range.
• Click inside the cell where the formula is (cell C5 for us)
• From the menu bar, click Insert > Name > Apply
• From the Apply Name dialogue box, click on the Name you want to use
• Click OK
• Excel will insert the name, if it can, and hide your cell references behind the name
So go ahead and insert a Named Range for cell C5. When you're finished, the spreadsheet
should look like the one below:
As you can see, cell C5 no longer reads = Sum(C2:C4). Instead, we have a Named Range
in cell C5.
In the next part, we'll see how to use the Named Ranges you have just set up.
In the previous part, you saw how to define and apply Named Ranges. In this part, you'll
learn how to use the Named Ranges you have just set up.
You might question the need to set up two more Ranges, on the grounds that we have just
set up two Named Ranges in cell B5 and C5.
Strictly speaking, we don't need the new names. To deduct the Tax from the Monthly
Total using Named Ranges we could just do this:
=Sum(Monthly_Totals) - SUM(Monthly_Tax)
And it would work. Excel would take one from the other. (The following, however,
would not: = Monthly_Totals - Monthly_Tax.)
But if we set up two more Named Ranges, we can just use the single totals, instead of
telling Excel to use a Function to add them up first.
Now that we have the Names defined, we can enter a formula and Apply the names into
the formula. First, amend your spreadsheet so that it looks like this one:
As you can see, a new label has been added, along with the formula in cell B7: = B5 -
C5.
Now that we have a formula we can replace the cell references B5 and C5 with the names
we set up. So click on B7 and do this:
When inputting data into a spreadsheet, often you will find yourself having to type the
same data into cells. That's where Data Validation comes in handy. Instead of typing the
same thing over and over again, you can turn the cells into drop-down lists. That way,
you could just quickly select an item from the list and move on to the next entry.
For example, suppose you had a column heading called "Student Grade". Even though
there are only two grades available, Pass and More Work Needed, it can become quite
laborious having to type either one or the other. Spelling mistakes will become
increasingly more likely the more times you have to enter the grades. Much better to have
a drop down list where you could select the grade. And no more spelling mistakes!
Data Validation
We'll now construct a spreadsheet with drop-down lists. The one we're going to construct
takes us back to the classroom and our students from previous section.
Before we can turn the cells in an entire column into drop down lists, we need some data
to go in the lists. So starting at cell F2, add the following to your spreadsheet:
The data in columns F, G and H will be going into our lists. We can then hide this data so
that it's not messing up our spreadsheet. You'll see how to do this later. But we can now
turn Columns A, B and C into lists.
• Highlight the whole of Column A by clicking on the letter A at the top of the
column
• With the whole of Column A highlighted, click on Data from the Excel menu bar
• From the drop down menu, click Validation
• The following dialogue box appears:
The Source is the data that is going into your list. So you need to select the cells with the
students in them. To select the cells with the students in them, do this:
• If you have done it all correctly, your dialogue box will now look like this one:
So the Validation criteria should be: "Allow List", and the Source should be =
$F$2:$F$9.
Click OK when your dialogue box reads the same as the one above. The cells in you
entire A column will now be drop down lists. Test it out. Click on cell A3, for example. It
should look like this:
If you click the black down arrow, you should see your list of students. Like the one
below:
Click on any student in the list. The student appears in cell A3. Click on another cell in
column A and try it again.
I'm sure you'll agree that it's much better than having to type out a student's name over
and over again.
Except we have a slight problem. If you click inside cell A1 you'll see that this too has a
drop down list. Clearly we don't want this to happen for our heading. To turn off the list
in cell A1, do the following:
Time for you to try it alone. Change the Subject and Grade columns into drop down list,
and then turn off the list for the headings cells B1 and C1.
The drop down lists for the Subject and Grade columns should look like these when
you're done:
In the next part, you'll learn how to display error messages. That way, you can control
what data your users are allowed to enter.
n the previous part, you created drop down lists so that you can simply select the data you
want, rather than typing it in all the time. In this part, we'll display error messages if a
user types in too much data.
We can add Validation to the Comments field in our spreadsheet. We'll restrict the
amount of text that can go in the Comments field to a maximum of 25 characters. The
comments field you should have is this one:
So highlight the Comments column and bring up the Data Validation dialogue box again
(Click Data > Validation from the menu). This time, in the Allow drop down box select
"Text Length". A few more fields will appear on the dialogue box:
The Between in the Data text box is exactly what we're looking for. But we need to enter
values for the Minimum and Maximum fields. These are the Minimum and Maximum
text lengths that can put in any cell in the comments column. We'll restrict the length to
25 characters, just so you can see how it works.
We can add an error message, too, so that we can tell users what they did wrong. To add
an error message, do the following:
• Click on the Error Alert tab strip of the Data Validation dialogue box
• The dialogue box will change to this:
If your dialogue box doesn't look like the one above, make sure there is a tick in the box
at the top "Show error alert after invalid data is entered."
There are three different Styles you can choose from for your error message. Click the
black down arrow just below Style to see them. Click on each one in turn and see what
happens. Then set it back to Stop.
• Click inside the Title text box and type "Too many characters"
• Click inside the Error message text area and type "The maximum number of
characters for this field is 25 - please try again"
• Your dialogue box will then look like this:
Click OK when you've finished. To test it out, click inside cell E2 and type the following:
Steven can do a lot better than this. Then press the return key on your keyboard. Your
error message should pop up and look like this one:
The error alert gives the user the changes to either Cancel the data already input, or to
Retry.
The only thing spoiling the look of our spreadsheet are the cells starting at F2, the ones
from our list. We can hide all that data from prying eyes.
Now try this. Click anywhere on the D column. Click Format > Column > Unhide.
What happens?
It's because you did not tell Excel which columns you wanted to Unhide. To do that,
highlight columns E and I. Then click Format > Column > Unhide. Your data should
return.
If you don't want anyone else to Unhide your data, you can Protect the worksheet from
unwanted changes. Just click on Tools > Protection > Protect Worksheet. A dialogue
box appears. Select your options, and then click OK.
And that's it for our brief look at Forms. You can do a whole lot more with Forms, but
that enough for us. We can move on to Web Integration.
Excel: Filter a single column based on 3
or more criteria
Question: I have an Excel spreadsheet and I would like to filter more than 2 types of
criteria from a single column. The custom AutoFilter only allows for up to 2 at a time.
How can filter a single column based on 3 or more criteria?
Answer: You can filter a single column based on 3 or more criteria by applying an
advanced filter. To do this, open your Excel spreadsheet so that the data you wish to filter
is visible.
In a blank column, add the column heading and the values that you'd like to filter on. In
this example, we want to filter the Order ID column to display the orders 10248, 10251,
and 10253. We've typed these values into column F.
Highlight the data that you wish to filter. We've highlighted columns A to D.
Next, select the Criteria range. These are the filter values. In our example, we've entered
the filter values into cells F1 to F4. (ie: Order IDs 10248, 10251, and 10253). Then click
on the OK button.
Now when you return to your spreadsheet, your data should be filtered. (Note: The row
numbers on the left will appear in blue when your data has been filtered.)
Answer: You can filter multiple columns based on 3 or more criteria by applying an
advanced filter. To do this, open your Excel spreadsheet so that the data you wish to filter
is visible.
In a blank column, add the column heading and the values that you'd like to filter on. In
this example, we want to filter on both Order ID and Quantity. The filter should display
all records with the following conditions:
Next, select the Criteria range. These are the filter values. In our example, we've entered
the filter values into cells F1 to G4. Then click on the OK button.
Now when you return to your spreadsheet, your data should be filtered. (Note: The row
numbers on the left will appear in blue when your data has been filtered.)
Question: After I've sorted my data and I'm in 'filter mode' (the numbers are highlighted
in blue), is there a way that I can actually save that filtered data and filter it again
(perhaps in 'auto filter') without losing my original filter? (ie. If I've filtered data lines 1-5
and the final results show lines 1,2 and 5 , can I filter again and not have lines 3 and 4
show up?)
Answer: To apply one filter and then another filter without losing the original filter,
select a cell within the data that you wish to filter. Under the Data menu, select Filter >
AutoFilter.
Next, apply your first filter. In this example, we've selected to filter by "Boston Crab
Meat" as the product.
In our example, we see only 3 rows where the product is Boston Crab Meat.
Next, apply your second filter. We've selected an Order ID of 10267. This second filter
takes the filtered data and applies a second filter to this data.
Now our spreadsheet will display only those rows whose product is Boston Crab Meat
and whose Order ID is 10267.
Excel: Copy filtered data to a new
worksheet
Question: I've filtered my data in Excel and I want to copy the filtered data to another
worksheet. How do I do this?
Answer: In newer versions of Excel, the copy of filtered data does not copy the hidden
rows. Because of this, we will provide a few scenarios on how to copy filtered data.
To do this, open your Excel spreadsheet and select the filtered data. Press Ctrl-C to copy
the data.
Next, select the worksheet where you'd like to paste the data. Press Ctrl-V to paste the
data into the new worksheet.
The data that is pasted will only be the visible data from the filter. The rows that were
hidden by the filter will not be pasted.
To do this, select a cell in one of the filtered rows. Under the Data menu, select Filter >
Show All.
Now all of the rows should be visible. Select all of the data and press Ctrl-C.
Next, select the worksheet where you'd like to paste the data. Press Ctrl-V to paste the
data into the new worksheet.
Now all of the rows should appear in the pasted data. You can now re-apply your filters.
Question: In Excel, I'm trying to put a chart in alphabetical order. There are 4 columns
and over 2,000+ rows of information. Only the first column needs to be placed in
alphabetical order. How do I do this?
Answer: To apply a sort in Excel, highlight the data that you wish to sort.
Under the Data menu, select Sort.
When the Sort window appears, select the columns that you wish to sort by. In our
example, we are going to sort the Product column in ascending order.
These vendors sell password recovery software. I haven't tried any of them.
• AccessData
• Crak Software
• Elcomsoft
• Erlandsen Data Consulting
• Excel Key
• Excel Password Remover (free)
• Fast Data Recovery Lab
• Intertek
• MSOfPass97
• Password Crackers Inc.
• PWD Service
• PW Finder
Non-English Links
Non-English Excel Links
• Add-In World
German - add-ins and newsletter from SmartTools Publishing
• AO-Excel
Hebrew
• Aquira's Excel-VBA Memorandum
Japanese
• DataSpectrum
Czech
• De Web-Expert
Dutch
• Desarrollo de Soluciones con Microsoft Excel 97 / 2000
Spanish
• Die MacHero Excel Homepage
German
• Excelabo
Frency
• Excelformeln - ÜBER UNS
German
• Excel - arkusz dla kaŜdego
Polish
• Excel Downloads
French
• Excel Inside
German
• Excel pour les statistiques, la qualité et l'intelligence artificielle
Frency
• Excel VBA Access
French
• Excel Expert Training
Thai
• Excel Mailing List
Portuguese
• Excel Skill Training Hall
Japanese
• Excel przyjazny Tobie
Polish
• ExcelSpecialist
Dutch
• Excel Turkiye
Turkish
• Exemples de programmation Excel VBA
French
• FAQ du forum Microsoft.Public.Fr.Excel
French
• Fernando Cinquegrani
Italian (great charts!)
• Free Add-Ins For Excel
German
• Hans Herber
German
• Herzlich Willkommen
German
• Idema Design
Dutch
• Jiri Cihar, Dataspectrum
Czech
• J-M Lambert
French
• Kent's Excelsida
Swedish
• Laurent Longre - Compléments Excel 97-2000
French
• Mabat3
Hebrew
• Monika Weber's Office Help Desk
German
• Mixa Excel FAQ
Russian
• Mondial
Portuguese
• netprof.ch
German
• Office Assistant
French
• Ole P.'s Excel Tips
Norwegian
• PolyKromy
English and French
• Poradnik Excela / Excel's Vademecum
Polish
• Rang-x
Spanish
• Rente in Excel
Dutch
• Rolf's Page
German and English
• Schmitti's Page
German
• Statistik mit Excel
German
• Technical Calculations
Czech and English
• Uno's LIbrary
Korean
• Web-Expert
Dutch
• XL-Dennis
Swedish
Excel Consultant Links
Excel Consultants
These links take you to the web sites of consultants who work with Excel. Listing a
consultant here does not constitute an endorsement. They are listed for your convenience
This section contains links to a variety of publications (printed and electronic) that
deal with Excel.
The links below lead to sites of third-party developers and shareware authors who
provide Excel-related products. Listing a product here does not constitute an
endorsement. They are listed for your convenience.
• 2000 Tools
Home of DateSpy - Identify Y2K risks.
• 4Tops
Access and Office products
• Abstract Pro
Lease Manager v 2.0
• Accmatrix Accounting
A fully integrated, multi user client/server accounting software product that uses
Excel as a front-end
• ActiCalc
An Excel-compatible desktop calculator.
• Adarus
Business Plan: An add-in and template for preparing business plans.
• Advanced Numerical Methods
Abacus, an engineering function library
• AlgoLab
Raster to Vector Conversion Toolkit
• Alyuda
NeuroSignal XL - neural network add-in for stock prediction
• alphaWorks
ExcelAccessor bean suite (access Excel workbooks from Java)
• Alyuda
Alyuda Forecaster XL. An add-in for forecasting and data analysis based on
neural networks
• Analyse-It
Statistical add-in
• Analyzer Ltd
AnalyzerXL: Stock market technical analysis tool
• Angoss Software
Data mining solutions
• Applied Decision Analysis
DPL: Excel-compatible decision analysis software
• Bentz Engineering
Interactive 3D Dynamic Data Viewer
• Beside Software
Import Wizard for Excel
• BitStar
BrainSheet: Data analysis using neural network techniques
• Brandywine Software LLC
Makers of Spreadsheet xlNavigator and Analyze with xlEquations
• Builder Place
Construction industry costing and estimating
• Business Calculators
Add-in that automatically crates Excel user-defined functions
• Business Functions
Function library for financial planning and analysis
• Byg Software
Byg Utilities, Excel Auditor
• Calibrex
Finance tools for Excel
• Chemeng Software
Fluid Flow spreadsheet templates, for use by chemical and mechanical engineers
• ChemSheet
Thermodynamic calculations
• The Chicago Innovative Business Alliance
Visual Baler spreadsheet compiler
• Cimware
Software to recover damaged MS Office files
• Communication Enhancement Products
Distributed Spreadsheet: Planning, budgeting, forecasting tool
• CompuQuest
SpreadMsg Lite: monitor stocks, etc.
• Compressia
Spreadsheet file compression utilities
• Concept Data
Recover data from corrupt Excel files.
• CPR International
Home construction cost estimator
• CustomGuide
Computer courseware for Excel (and other products)
• D.A. Martin Software
SPC Orchestra: Statistical Process Control
• DataTrend Software
Graph digitizing software for Excel
• Data Shaping Solutions
Real-time strategy design, backtesting, and implementation
• Data Instrument Group
DIG: Data analysis tool
• DataShenk
Excel training
• DateWise, Ltd.
Abater for Excel
• Decision Models Ltd.
FastExcel
• Decision Support Systems
Decision-tree add-in (shareware)
• Decisioneering
Crystal Ball forecasting and risk analysis add-in.
• Decision Systems Inc
Web-based management reporting using Excel
• Derivicom
Financial Add-ins for Excel: FinOptions XL and FinExotics XL
• Dimensions 5
Miner3D for Excel
• DirtSoft Construction
Constuction management and personal productivity templates
• DJI Computer Solutions
Tax Assistant, Golf Tracker, Checkbook, Handicap Manager, Task Manger
• DPS Payroll Service
A home page about spreadsheets and programming
• Shale Software
Mapping software
• Sheetware
Products for spreadsheet users
• SM Software
Delphi and ActiveX libraries and components for working with Excel files
• Software Illustrated
MapLand: mapping Software for Excel
• Sonalysts, Inc.
Fuzzy Query for Excel
• Spreadsheet Detective
Auditing tools for Excel
• Spheresoft
Spheresoft Modeler and Spheresoft Highlighter add-ins
• Spreadsheet Auditing
Excel auditing application
• Spicer-Baer Associates
PerpetualBudget spreadsheet networking application
• Spinnaker Software Solutions
List/Dbase add-ins, Alerts, and Stats.
• Spredgar Software
EDGAR financial ratios and graphs
• STAAP
An album program for stamp collectors
• SyTech
Automated report generation
• TA-LIB Technical Analysis Library for Excel
Use programming languages like C++, JAVA, and Visual Basic to analyze stocks
and commodities
• TechHackers Inc.
@nalyst financial functions add-in
• Tidestone Technologies
Formula One: Spreadsheets on the Web using Java and ActiveX
• UDA
Excel templates for estimating construction costs
• Universal Class
Online course: Excel Basics for Beginners
• u-turns
Body Fitness Profile Test
• Vertex^42
Niche Excel Solutions
• Vertigraph, Inc.
BidPoint XL: Excel add-in for digitizers (construction management)
• Visual Numerics
Smart Table: Converts spreadsheets to Java without programming
• Vista
Excel report builder
• VORSIM
A framework for building spreadsheet simulation models
• Windmill Software Ltd.
Software to acquire data from serial instruments and send it to Excel
• Wingate Financial Engineering
iLib: Financial add-in library
• xlCBT
A CBT authoring tool for Excel
• XL Consulting GmbH
Synkronizer for Excel
• xlCubed
Reporting within Excel against Microsoft Analysis Services
• XLMiner
Techniques for classification, prediction, affinity analysis, data exploration, and
data reduction.
• xlSTAT
A statistical add-in (English and French).
• xlStockCharts
Create stock charts from data on the Net
• XYFIT
Curve-fitting
• ZCalc
Templates and functions for tax and estate planning
General Excel Links
General Excel Information
The links below are of use to developers. Some of these sites also include information
relevant to non-developers.
• AddReg
AddReg - a utility that will automatically load your Excel add-in in as part of the
installation process.
• Alan Beban
Array Functions: 23 procedures for manipulating arrays
and ranges
• Alan's Excel Goodies
VBA code examples, formula and custom function examples
• Ananda's Access Coach eHome
A resource for Excel and Access users
• Anthony's VBA Page
VBA examples, mostly financial and statistical applications
• Apps Pro
Rob Bovey's Excel utilities
• Astronomical Functions (VBA)
By Keith Burnett
Microsoft's web site contains a wealth of information, but it is probably one of the worst
sites in the world in terms of ease of navigation. To make matters worse, the site is
constantly changing so links to specific pages are often broken.
An example of why you would want to download data from a website is this.
You are salesperson out in the field, visiting clients in their homes or offices. You have a
laptop that can connect to the internet. There is a spreadsheet on your laptop. The
spreadsheet includes lots of data about the products you sell. One piece of data is the
prices of each item. Your company is rather ferocious on prices, and it changes them all
the time. The question is, how can you, as a salesperson in the field, keep up to date with
the changing prices?
One answer is to use an Excel Web Query. The company will update the prices on the
website. You can then run a Web Query to download the latest changes into your Excel
spreadsheet. That way the clients get the new prices "Hot of the Presses".
We'll see how to run a Web Query soon. But you need a connection to the internet before
you can run a Web Query. In other words, you need to be online. (However, if you know
some HTML coding, you can construct a table in a web page that is on your own
computer. Then you point the Web Query to the web page on your computer, rather than
a web page on the internet. Don't worry if you don't know any HTML coding - it's not
necessary for this section.)
But don't go online just yet. Read a few more pages first.
You create a web query in Excel when you want to pull data from an internet page and
pop it into a spreadsheet. You can retrieve text from a web page, data in tables, and data
that is preformatted on the web page.
There are three sections to the dialogue box. The first section is where you type in the
address of the internet page that you are trying to pop into Excel; the second section is
where you specify which part of the web page you want to insert into your spreadsheet;
and the third section sounds a bit technical, but basically you are choosing the type of
formatting to use: do you want to keep the colour scheme, or strip it bare?
In the first section, you need to type in the name of our internet page. The internet page
contains a table with some product information and some prices. By all means, load it
into your browser and have a look at it. But first, you need the address. So:
• In the text box right at the top of the dialogue box, type in this internet address.
Make sure you spell it exactly as it is below:
http://www.homeandlearn.co.uk/ME/webquery1.htm
• When you have typed the address in the text box, Select "The entire page" from
section 2 of the dialogue box.
• From section 3 of the dialogue box, select "None"
• Click OK when you're done
When you click the OK button, another dialogue pops up. This time your are asked where
in your spreadsheet you want to put the data. You only need to specify the starting cell.
The dialogue box looks like this:
The dialogue box is already set up to put your data into the spreadsheet starting at cell
A1. But you could change that, if you wanted. Cell A1 is fine for us, so just click the OK
button.
Excel will now look for the internet address you typed. When it finds the web page, it
will then take the text and the contents from the table and put them into your spreadsheet.
If the Web Query seems to be taking too long, you can Refresh it. To do that, click on
View > Toolbars > External Data. A toolbar pops up on your page. Click the Refresh
icon, as shown below:
If everything goes well, you should have a spreadsheet that looks like the following one:
As you can see, Excel has imported the data from a web page on the internet into a
spreadsheet. You now have a way to get the latest prices from Head Office!
In the next part, we'll import a web page with better formatting.
The problem with the spreadsheet in the previous section is that it looks a little dull. This
second web page you're going to download into Excel is little more colourful. So do the
following:
http://www.homeandlearn.co.uk/ME/webquery2.htm
Although the table itself might look nice and bright, that text heading looks chopped of.
Your heading might look like the following one:
The reason it's chopped of is because the cells on row 1 are not formatted properly. If you
highlight row 1, from A1 to G1, and then click Format > Cells from the menu bar, you
can merge all those cells, and centre the text (Alignment tab strip, centre, tick box at
bottom "Merge Cells".)
The image below shows a tidied up version of the downloaded spreadsheet (you can do
all the cell formatting before you download):
And that's all there is to the basics of downloading data from the internet and importing it
into an Excel worksheet.
If you have a lot of different worksheets and want a quick way to jump between them,
you can use Hyperlinks. Hyperlinks are those underlined bits of text on the internet that
lead to web pages
To get a feel for how they work in Excel, start a new spreadsheet and do the following:
We're going to place links in specific cells of three different worksheets. So:
• Locate the text area under "Or select a place in this document"
• If there is a Plus sign ( + ) next to "Cell Reference", click on the plus sign to
expand it. You should see the same choices as in the image above
• Click on "Sheet 3
Now that we have a selected a page to link to, we can specify that Excel goes to a cell of
our choice:
• In the text box below "Type the cell reference", type in C10
Our A1 cell has nothing in it. So to insert some text for our link, do this:
Click the button in the top right of the dialogue box "Screen Tip". Another dialogue box
pops up, like the one below:
• Click inside the text box and type "Jump to Sheet3 Cell C10" (without the quote
marks.)
• Click Ok to return to the main dialogue box
• On the main dialogue box, click OK again
• A hyperlink will be inserted into cell A1 of Sheet 1
• Move your mouse pointer over cell A1
• Your spreadsheet will look like the one below:
Click on the link and see what happens. Now it's your turn to try it.
Exercise
In cell C10 of the spreadsheet, insert a Hyperlink to take you to cell B10 of Sheet 2. Add
a suitable Screen Tip.
In cell B10 of sheet 2, insert a Hyperlink to take you to cell A1 of Sheet 1. Add a suitable
Screen Tip.
And that ends this somewhat brief introduction to Web integration. There a whole lot
more you can do with Excel and an internet connection: Upload data from a spreadsheet
to a web page; Save a spreadsheet as a web page; Publish a spreadsheet to web page that
others can interact with; Hold an Online discussion. In fact, an entire book could be
written on Excel and the Internet!
To wrap up this Excel course, the final section details a few Extra things you can do with
Excel. It starts with something called Object Linking and Embedding.
Spreadsheets are inserted into Word documents using something called Object Linking
and Embedding. Object Linking and Embedding (or OLE), can be a complicated subject,
but basically it's used when you want to insert something from one programme into
another programme. The example you're going to see will embed a spreadsheet chart into
Microsoft Word.
You have two choices when you want to embed something from Excel into another
programme - to use linking, or embedding. If you use linking, you can update the data in
Excel and see the changes in the other programme; if you use embedding, any changes
you make to Excel will not show up in the other programme.
First, here's how to create a Linked Object. The two programmes used will be Excel and
Word. So if you have Microsoft Word and Excel, open up both programmes.
In Excel, create the following spreadsheet:
All the spreadsheet does is multiply whatever is in cell E1 by 12. The answer goes in cell
E3. (This example is not terribly functional: you wouldn't really want to use OLE with
this particular spreadsheet. But it's easy to create, and will serve as an example of how to
use Linking.)
Word now goes to work and embeds your spreadsheet into the Word processed
document. Because we chose Paste Link, we will be able to view any updates made from
Excel. The Word document should look like the one below:
To see that it really does update in Word, do this:
As you can see, the numbers from the Excel spreadsheet are now in the Word document.
The link worked!
If you don't want Word updating the embedded object, you would select Paste instead of
Paste Link from the Paste Special dialogue box. Everything else is the same.
Things like Charts and Pivot Tables are the ones usually embedded into a Word
document, all ready for the company presentation.
In the next part, we'll see how to reference formulas and data on other worksheets
You can put the answer to a formula on a different worksheet. It doesn't have to go into
the same sheet you're working on. For example, think back to the exam marks
spreadsheet we did earlier. We had a spreadsheet that had the average scores for the
students. Below that we had each exam mark as a letter of the alphabet: A, B, C, etc. The
spreadsheet we created was this one below:
Instead of putting all those Grades on the same Sheet, we could have put them on Sheet2
of the Workbook.
If you want to put a formula on a different work sheet, you have to set a reference to the
Sheet that contains the numbers going into the formula. An example might clear things
up.
=Sheet1!A1 + A2
• Press the Return key on your keyboard
• Excel should give you the answer 4
Four plus five is clearly not four, so what went wrong? Well examine the way we set a
reference to the sheet that held our numbers. It was this:
=Sheet1!A1
When you are setting a reference to a different worksheet, you need the name of the
Sheet. Then you type an exclamation mark (or a bang as it's sometimes known). You then
type the cell that you are referring to. So in our formula, we were saying to Excel "Find
the worksheet that has the name Sheet1. Now find Cell A1 on the workbook called
Sheet1."
=Sheet1!A1 + A2
For the second part of the formula, we have + A2. But we haven't told Excel the name of
the Sheet we're referring to. We've just put A2. If the cell reference in the formula doesn't
have the name of a worksheet in front of it, Excel will assume you mean the current
worksheet. Our current worksheet is Sheet2. Cell A2 of Sheet2 is empty. So the formula
adds up the number 4 from cell A1 on Sheet1 and the blank cell A2 on Sheet2. Which
gets an answer of 4.
To solve the problem, tell Excel that you want to take the number from cell A2 on
Sheet1. So change your formula to this:
=Sheet1!A1 + Sheet1!A2
The main point to bear in mind when referencing data that is on another worksheet is this:
Give Excel the name of the worksheet followed by a Bang!
In the next part, you'll learn how to Insert Drawing objects into your Spreadsheets.
You can draw on your spreadsheet. You can even put a picture on a spreadsheet.
Sometimes a drawing can help to illustrate the data or function on the spreadsheet. The
drawing in the spreadsheet below is illustrating what the function does:
We'll see how to draw and format the triangle shape now. (Don't worry about all that
Cosine stuff. But we'll give you the formula, just in case you want to duplicate the
spreadsheet exactly.)
Before you can draw shapes on your spreadsheet, you need to display the Drawing
Toolbar. To display the Drawing Toolbar, do this:
The Drawing Toolbar should appear, but it might be at the bottom. It looks like this:
Click on AutoShapes to see the kind of shapes you can add to Excel. To get the triangle,
do this:
The white squares around the shape are the sizing handles. To resize your triangle, move
your mouse over a white square. The pointer will change to the shape of a double-headed
arrow. Hold down the left mouse button and drag. To move the triangle somewhere else,
move your mouse pointer somewhere in the middle of the shape. When your mouse
pointer turns into a arrow-headed cross, hold down the left mouse button and drag the
shape somewhere else.
To add some colour to your shape, again Right click on the shape and select Format
AutoShape. This time, select the Colours and Lines tab strip. Click the down arrow of the
"Fill Color" box. Choose a colour for your shape.
To add the letter B to your triangle, you need to add a text box on top of it. So, locate the
Text Box tool on the Drawing Toolbar. Click on it with your left mouse button. Position
your mouse at the bottom of your triangle. Hold down the left mouse button and drag out
a text box. Your spreadsheet will look something like this one:
Click inside the text box and type the letter B. Now click on one of the edges of the text
box, somewhere near a white square. But click with your Right mouse button. A menu
will pop up. When the "Format Text Box" dialogue box appears, select the Colours and
Lines tab strip. Under "Line Color" set it to No Line, as in the image below:
In the "Fill Color" box, set it to No Fill. Then click the OK button. Your final shape will
then look like this:
If you want to add the Cosine formula to the spreadsheet, it was this:
=DEGREES(COS(E4 / E5))
Cell E4 will then be the input cell for the Hypotenuse, and cell E5 will be the input cell
for the Adjacent.
In the final part, you'll see how to insert an image into a spreadsheet.
Excel’s VLOOKUP Function: How to Use
It and How to Nest It
by Linda Johnson, MOS
The VLOOKUP function is a handy one to know when you want Excel to lookup a value
in one place and insert it in another. For example, let’s say you have a list of all of your
customers on a sheet named “Accounts” and an invoice on another sheet named
“Invoice”. When you type in their account number on the Invoice, you want Excel to fill
in the name of the customer and their address (and this information is included for all
customers on the Accounts sheet). A VLOOKUP will do this for you.
Make a small sample workbook to try this out. Name Sheet One “Invoice” and name
Sheet Two “Accounts”. On the Accounts sheet, put three columns of data. Column A
would be Account Numbers, Column B would be Customer Name, and Column C would
be Address. Add at least five pretend customers, so you have enough to play with. On the
Invoice sheet, just add these five column headings in cells A1:E1 – Date, Product
Ordered, Account #, Customer Name, Address -but don’t put any data in there yet. (In
reality, this sheet would be an actual invoice which included sections for you to add
ordering info for any products they buy, etc. But for this example, let’s keep it simple.)
Now, before we try the VLOOKUP, the best thing to do is name the range of data that
includes the info you want to pull over from the Accounts sheet. You can do VLOOKUPs
without naming the range, but then you MUST be sure to use absolute cell references. So,
I find naming the range a much easier way to do it. Highlight all the data on the Accounts
sheet and name it Customers (don’t include the column headings in the named range –
just the data). If you don’t know how to name ranges, read this TechTrax article I wrote
on how to do that.
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=281
Now that you have your data and have named the range, let’s look at building a simple
VLOOKUP formula. Assume we will be typing account numbers into cell C2 and
wanting the customer’s name and address to be filled into D2 and E2.
The best way to learn new formulas is to use the Insert Function button . In Excel
97 and 2000, it's a button on your Standard Toolbar. In Excel 2002/2003, it's on your
Formula Bar. On the Invoice sheet, click into cell D2 and click on the fx button.
(The picture above shows how this box looks in Excel 97/2000. In 2002/2003 it’s slightly
different, but I think you can figure it out.)
If you know what type of function you are looking for, you can select the category and all
the functions within that category will be listed. However, if you don't know what
category you need, you can select "All" in the category list and all of Excel's functions
will be listed. Notice as you click on any function name, Excel displays a description of
what that function does below the boxes. For this exercise, select the "Lookup &
Reference" category and scroll down to select the VLOOKUP function. Note that it tells
you that this function “searches for a value in the leftmost column of a table and returns a
value from the same row in that table based on what column in that row you specify.”
Click OK.
Once you click OK, you will get the wizard which helps you with your VLOOKUP
formula. Now, because we will be typing an Account # in cell C2, that is the value we
must put in the first box of this wizard which will tell Excel to look for whatever is in C2
in the leftmost column of our lookup table (which we created on the Accounts sheet and
named "Customers"). So, enter C2 into the top box.
Click into the next box where it says "Table_array". Notice at the bottom of this box, it
tells you what each box you click inside needs. This is where we need to identify our
table so Excel knows where to look. So, in this box, simply type Customers. (If you
didn’t name the range, you will have to put the absolute reference including the sheet
name here … this is why it’s easier to just name the range.)
Click into the third box. This one wants to know the number of the column we want
returned. Remember that what you entered in the first box in this wizard must ALWAYS
be in the first column of your lookup table. So, in our table, the Account # is in the first
column and the Customer Name is in the second column. Since the customer name is
what we want to put here, just type a 2 to let Excel know we want what is in the second
column.
Notice the last box is labeled "Range_lookup" and it is the only label that is not bold.
Whenever a label in this wizard is not bold, that means this "argument" of the function is
not required. However, if you do not enter anything in this box, Excel will apply the
default. If you read the instructions at the bottom of this box, you will see that the default
for this box is "true" which will find the "closest match", whereas "false" will find an
"exact match". Since we want an exact match, type false in this box. This is what it
should look like if you have entered all the info correctly:
Click OK and you will see that cell D2 now shows #N/A, which simply means that there
is no value yet in C2, so the information is "not available". Look in your formula bar and
you will see the formula is =VLOOKUP(C2,Customers,2,FALSE). As you get more
used to using functions, you won't have to use the wizard as much if you take the time to
look at the formulas and start to understand how they work.
Now click into cell E2 and add a VLOOKUP formula which will find the Address in our
table. The formula will be exactly the same, except the "Col_index_num" will be 3
instead of 2 because we want to return the address, which is in the third column of our
table. Once you have added this, you should see another #N/A in cell E2. The formula
will be =VLOOKUP(C2,Customers,3,FALSE).
NOTE: All other information in the second VLOOKUP formula will be exactly the
same as the first one. We are still looking for the value that will be placed in C2. We are
still looking in the table named Customers. And we still want false for an exact match.
The ONLY thing that is different is we are now going to pull the information from
Column 3 instead of 2.
Move to cell C2 and type in one of the Account numbers you have in your Accounts
sheet and you will see Excel fills in the Customer Name and Address for that account
number However, if you type a number that does not exist on your Accounts sheet,
Excel will leave the #N/A because the information for that number is "not available
To see a VLOOKUP formula in action, go to this page at my website and view this
interactive formula:
http://www.personal-computer-tutor.com/vlookup.htm
Now that we've gotten more comfortable with VLOOKUP, let's look at nesting
formulas, one inside another. We can use the VLOOKUP formula we just made as a
starter.
Let's say we don't want to see that nasty old #N/A every time one of our VLOOKUP
formulas refers to an empty cell or value that is not in our lookup table. What we need to
do is tell Excel to show us the result of the VLOOKUP only IF it does not return a #NA
result and, otherwise, just leave the cell empty. So we need to use three different
functions in one formula: VLOOKUP, IF, and ISNA.
Intro to IF Statements:
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=225
Nesting IF Statements:
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=242
So, our criteria is IF the VLOOKUP returns #N/A, give me an empty cell, but if it
doesn't, give me the result of the VLOOKUP.
Let's try it. First we need to think about each of the three formulas and what they must
include. We already have our VLOOKUP formula and we already know what an IF
function must include, so the only one we need to learn is the ISNA function. All the
ISNA function does is return a value of true or false. True if the cell has a #N/A error
and false if it doesn't. So, since an IF statement wants to know if something is true or
false, these two functions work very well together.
Click into cell D2 in your Invoice sheet where your first VLOOKUP formula is.
The thing you need to understand is that when you nest formulas within formulas, Excel
performs the operation dictated by the deepest nested formula first, then works its way
outward. So, enter the following formula into cell D2, then enter an account number in
cell C2 that does not exist on your Accounts sheet and you will see that the #N/A error
does not show.
=IF(ISNA(VLOOKUP(C2,Customers,2,FALSE)),"",(VLOOKUP(C2,Customers,2,FALSE)))
NOTE: Be sure to include all the proper commas and parentheses. Remember that all
opening parentheses must have closing parentheses or Excel will give you an error
message.
Remember that Excel performs the deepest nested function first, so looking at the
formula above, you will see:
• The first thing Excel does is perform the first VLOOKUP (since that's the one that
is nested deepest)
• Then it performs the ISNA function on the result of the VLOOKUP to see if the
VLOOKUP gave a #N/A error or not. The ISNA function returns a value of true
if it sees the #N/A error and a value of false if it doesn't
• Then Excel performs the IF function on the result of the ISNA function. If it sees
a "true", it returns nothing (which is what the "" tells it). If it is "false", it returns
the result of the VLOOKUP function, which is what the last VLOOKUP function
is telling it to do if the value is false.
Getting the hang of it? Excel has other lookup and reference formulas that you can
explore using the Insert Function box. For example, HLOOKUP is similar to
VLOOKUP, but it looks for Horizontally laid out data, instead of Vertical. More
information on different lookup and reference formulas is available in this article from
my ezine, ABC ~ All ‘Bout Computers:
Excel VLOOKUP
Say you want to create an invoice that will automatically add the prices when you
enter the item numbers.
Create your invoice on Sheet One, and create a table of your item numbers and
their corresponding prices on Sheet Two.
In Sheet One you will add a VLookup formula that will pull the prices from Sheet
Two when you enter the item number on Sheet One.
Try it here. Change the item numbers in Cells A4 through A6 and see how the
price changes in Cells C4 trough C6.
Excel
A B C D E F
1 INVOICE TABLE
2
3 ITEM # QTY. PRICE ITEM # DESCRIPTION
4 101 2 $14.00 100 Hat
5 105 4 $70.00 101 Scarf
6 104 6 $192.00 102 Socks
7 103 Jewelry
8 104 Shirt
9 105 Tie
10
11
If you copy this formula down, note that A4 and B4 will change to A5 and B5,
then A6 and B6, and so on down the column.
Note that if your table is on Sheet Two, your absolute range (in this case,
$E$4:$G$8) would have to include the sheet name of Sheet Two and would
reflect the range of cells your table includes on that sheet and would look
something like Sheet2!$A$1:$F$15).
Note the "3" in the formula reflects the column number in the table where the
desired information is located. If you change this to a "2", the result would show
the information in the "Description" column instead of the "Price" column.
This is a simple VLookup formula. Try adding other columns to the table on
Sheet Two and adjusting the VLookup so it pulls from different columns.
Lookup tables are fantastically useful things in Excel. I remember when someone
showed me for the first time how to build a data table and perform some simple
lookups on it. For the first time, I began to realise just how powerful Excel could
be in the right hands.
In this article, I'll talk about what a data table is, why you might find it useful to
have one, and why and how you might want to interrogate it. We'll end with a
trick or two involving some nested formulae, but by the time we get there, it will
all make sense.
First of all, then, what's a data table? Well, there's one shown below:
You'll notice that some related data is set out in columns, each with a heading in
bold at the top. So many other functions in Excel can use those headings
intelligently, that I have always made it a habit to put them in. Data tables like this
have so many uses it's difficult to know where to start: phone number lists, CD
collections, customer lists, the uses are endless. But sooner or later, you're going
to want to extract data from such a list, perhaps for a mail merge or to fill in an
invoice automatically, say.
Probably the best way of learning about the LOOKUP functions is to ask some
questions and use formulae to answer them. For instance, look again at the data
table above. If I want to know Barbara's age, I can use a command called
VLOOKUP. It's called VLOOKUP because it looks up the data in a table, based
on finding the key in a Vertical list.
=VLOOKUP("Barbara",A2:C6,2,FALSE)
Of course, this will return the number 23, which is Barbara's age. Let's look
briefly at the format of the function. The first argument is the piece of data I want
to look up (what I call the 'key') in the first column. (This must always be in the
first column, but later on I'll show you how to find values based on a key in other
columns instead.)
The second argument is the range which contains the table, in this case A2:C6.
I'd normally have named this range, but you don't have to.
The third argument is the column number I want to return the value from. Looking
at the table again, the first column contains names, the second ages and the
third locations. Clearly, if I want to find Barbara's location, I'd put a 3 in this
argument, but since I want to know her age, I've used 2.
Well, of course there's an HLOOKUP to match the VLOOKUP, too. You'd use
this when your table is oriented left to right, rather than top to bottom. Here is an
example of what I mean:
I can use the HLOOKUP function to find what date Debbie's birthday falls in like
this:
=HLOOKUP("Debbie",F2:J4,3,FALSE)
This formula returns April. The arguments work the same way as for VLOOKUP,
except of course that the third argument refers to the row number rather than the
column number. On the whole, it's much better to organise your data tables
vertically, as in the first example, because a horizontal data table cannot be
sorted or filtered by Excel as easily as a vertical one, but there are times when it
has to be horizontal for some reason.
MATCH allows me to find the position of an item within a range. For instance, if I
want to know how far down in the list of names Charlie is, I can use this formula:
=MATCH("Charlie",A2:A6,0)
The return from a MATCH function is always a number, in this case the number 3
because Charlie is the third entry in the range A2:A6. The zero at the end there is
a bit like the 'FALSE' in VLOOKUP and HLOOKUP - optional but risky to omit.
When set at zero, it says: "Make it an exact match". Ninety-nine times in a
hundred, that's exactly what I want.
INDEX is the opposite of MATCH in a way. It tells you what the nth value in a
range is. For instance, who is in position 5 in the list? Easy:
=INDEX(A2:A6,5)
This returns the name 'Elvis' because he is the fifth item in the range A2:A6.
Like INDEX, the MATCH function doesn't seem to do anything out of the ordinary
so far. But the real power of these functions only becomes apparent when you
combine them.
Look at the vertical data table again and consider how you'd find out who lived in
Belfast. The two LOOKUP formulas are no use, because the key value is not in
the first column. Remember, VLOOKUP can only read values to the right of the
key and HLOOKUP can only read values below the key.
But, look at it another way. I can break the question down into two smaller ones,
like this:
Put in those terms, it is pretty clear. The first question can be answered, of
course, by using a MATCH function:
= MATCH("Belfast",C2:C6,0)
This will tell us that Belfast is number 4 in the list, so we can put the number 4
into an INDEX formula:
=INDEX(A2:A6,4)
Of course, this formula will return the name 'Debbie', which answers the original
question. But in the same way that original question is made up of two sub
questions, so we can turn our two formulas into a single one, like this:
=INDEX(A2:A6,MATCH("Belfast",C2:C6,0))
Of course, we've looked so far at simple tables, and it's been far quicker just to
look at our table and answer the questions than to sit down and write formulae!
However, there will be times when the data tables are huge, or when you want
Excel to work things out for itself and get on with things. At times like those, you'll
find that the LOOKUP functions of Excel are an invaluable part of your toolkit.
Excel Functions: Financial functions and
formulae
Excel contains many financial functions and this page includes examples of PMT, PPMT,
FV and IPMT. These calculate compound interest, loan repayments and outstanding
principal amounts. Many other functions are only available if you load special add-ins
after installing the Analysis Toolpak (see Help | Financial Functions). Also included on
this page are some formulae with which values can be calculated without using built in
functions.
The following example shows the results of various financial calculations based upon
both Annual and Monthly values. Note that the cells C4:D8 have all been given names
ending with '_A' (annual) or '_M' (monthly). The names have been used in the formulae
rather than the cell references.
These formulae all assume a steady rate of interest. This is unlikely over a number of
years and so the calculations may need to be broken down into several separate elements,
each using different rates. [See how ...]