Read an Excerpt
Excel 2007 for Scientists
By Gerard M. Verschuuren
Holy Macro! BooksCopyright © 2008 Dr. Gerard M. Verschuuren
All rights reserved.
NAVIGATION IN EXCEL 2007
Excel 2007 has plenty of space for your scientific work. Each workbook (or .xlsx file) can hold an unlimited number of worksheets (provided that your computer memory permits), and each worksheet has a capacity of 1,048,576 rows by 16,384 columns. Hopefully, you won't use all this space before retirement.
Scientific spreadsheets can be huge — filled with many numbers. So you need ways to quickly navigate around and to create formulas for giant ranges of cells in a swift and efficient way. That's what this chapter is about.
Most sheets in this book have a modest size, so it is easy to practice with them. But in real life, you probably deal with much larger collections of data. The basic techniques discussed in this chapter will benefit you even more when your tables become larger and larger.
The following keystrokes are some important navigation shortcuts:
Ctrl+Home takes you to the origin of the sheet, which is cell A1.
Ctrl+arrow key jumps between section borders. (A border is an empty row and/or column.)
Ctrl+Shift+arrow key jumps and selects what is between the section borders.
Shift+arrow key expands or reduces whatever has been selected.
Let's use Figure 1.1 to see how these shortcuts work. Based on Figure 1.1, the following would happen:
Starting in A1: Pressing Ctrl+Down Arrow takes you to A24 and then to A1048576. Pressing Ctrl+Up Arrow takes you back, with the same stops on the way.
Starting in B1: Repeatedly pressing Ctrl+Down Arrow jumps to B10, B14, B23, and finally the end.
Starting in B1: Pressing Ctrl+Shift+Down Arrow selects the entire range B1:B10. Pressing Shift+Down Arrow once expands the selection with one more cell. Instead pressing Shift+Up Arrow shortens the selection by one cell. The Shift key keeps all in-between cells included in the selection.
Starting in J1: Typing J24 in the Name box just above column A and then pressing Shift+Enter selects all cells between J1 and J24 (thanks to the Shift key). With the range J1:J24 selected, typing =ROW () in the formula bar and then pressing Ctrl+Enter causes all the selected cells to be filled with this formula (thanks to the Ctrl key).
Figure 1.2 shows an example of how to create some formulas:
1. Select cell F11 and press the fx button (located just in front of the formula bar).
2. Choose the function STDEV and start the first argument by clicking cell F10 and the pressing Ctrl+Shift+Up Arrow; this selects the entire range above cell F11. Often, Exce finds the correct range automatically — but not necessarily so; when it doesn't, you hav to be in charge yourself!
3. Press OK in the dialog, and the cell shows the actual standard deviation of these cells.
4. In cell B24, use the function COUNTIF and follow these steps:
i. For the first argument, click cell B23 and then press Ctrl+Shift+Up Arrow.
ii. For the second argument, type >=5 (which changes into a string: ">=5").
iii. Finalize the functions by pressing Ctrl+Enter.
Figure 1.3 shows a quick technique for calculating the mean or standard deviation of certain measurements per strain of bacteria and per test:
1. Select cell A1 (or press Ctrl+Home).
2. Press Ctrl+Shift+Down Arrow and Ctrl+Shift+Right Arrow.
3. You need an extra row and column for the calculations of the means, so to expand the selection with an extra row and column, press Shift+Down Arrow and Shift+Right Arrow.
4. From the drop-down button next to the Sum button, choose the option Average, Min, or Max.
All calculations are done automatically at the end of each numeric row or column. You could do this more tediously; go ahead if you like that route better!
Figure 1.4 shows the same table as Figure 1.3, but this time in the dedicated table structure available in Excel 2007. Follow these steps:
1. Click the Table button in the Insert menu to create a table structure with a striping pattern for easy reading.
2. After the table structure is implemented, use the Design menu to change table settings as desired.
3. To create calculations again for mean and standard deviation, use the same technique you used earlier.CHAPTER 2
THE FILL HANDLE
One of the best-kept secrets in Excel is the fill handle. This tool allows you to copy cells over a contiguous range of cells or to fill such a range with a series of specific values. In addition, it helps you copy formulas over huge ranges.
The fill handle is located in the lower-right corner of your selected cell(s). Whenever you move your mouse to that location, the cursor will change to a small + sign (not to be confused with a crosshairs). That very spot holds the fill handle.
Figure 1.5 shows some examples that help you to explore some of the features of the fill handle:
Cell A2: Click and drag the fill handle downward to cell A6 in order to stop at Friday. If you keep going, the fill handle goes into Saturday, and so on. If you stop at Friday and then start the fill handle again (with A2:A6 still selected), you can just copy the previous section by holding the Ctrl key down until you are finished.
Cell B2: To insert the number 8 in column B for every day of the week, double-click the fill handle of cell B2. A double-click on the fill handle copies the content down to the first empty cell in the previous or next column. So the double-click does not work when there is no column with data to the immediate left or right.
Cell C2: Double-clicking the fill handle of cell C2 gives you a series of 1s. To change this into an incrementing series, click the button that has popped up and select [??] Fill Series. Now the series increments by 1.
Cells D2 and D3: For a series that needs to increment by a value different from 1, create a pattern in the first two cells, select both cells, and then double-click.
Cell E2: If you don't want to create a pattern ahead of time, double-click the fill handle of the first cell only. Now go to the Fill button drop-down (located under the ä button on the Home tab) and then choose the option Series. Specify any step value (for example, 2).
Cell F2: To multiply D2 by E2, follow these steps (you will appreciate them someday!):
1. Select cell F2.
2. Type the equals sign (=).
3. Press Left Arrow twice to get to D2 (that is, do not type D2).
4. Type the multiplication sign (*).
5. Press the Left Arrow key once to get to E2.
6. To finish, press Ctrl+Enter (not just Enter).
Note: What is the advantage of pressing Ctrl+Enter instead of Enter only? You stay in the same cell, so you can just double-click the fill handle to copy the formula all the way down. (Otherwise, you would have to go back to the previous cell first.)
Cell G2: If you always work with the same analysts in the same order, type their names once, select them all, and double-click the fill handle. If you want to use this same list over and over again — especially if it's a long list — use the following technique:
1. If you have a listing on your sheet already, select that listing first.
2. Click the Office icon in the left-top corner.
3. At the bottom of the new box, select Excel Options.
4. In the Excel Options dialog, choose Popular (in the left panel).
5. Click Edit Custom Lists.
6. Accept the highlighted list.
7. Click the Import button.
8. Click OK twice.
Now you can use this list anywhere in Excel. Just type the first name of this (potentially long) list and double-click the fill handle — provided that there is a column with contents to the left or right. Excel does the rest!CHAPTER 3
RELATIVE VS. ABSOLUTE CELL REFERENCES
Each cell on a sheet has a certain position. When you copy a cell that contains a formula to another position, the formula's cell references automatically adjust. Those references are called relative. Sometimes, you do not want formula references to adapt to their new location; in that case, you make them absolute.
To see how relative and absolute cell references work, take a look at Figure 1.6. Cell C1 has a formula in it: =A1*B1. You can copy the formula in cell C1 down by double-clicking because, in this case, you do want the cell references to change! How can you see all formulas at once? Use the shortcut Ctrl+~ (the tilde is located under the Esc key). Notice that Ctrl+~ causes all cell references to be relative here — which means: "Multiply two-cells-over-to-the-left by one-cell-over-to-the-left."
In cell F2, however, you want to find out what the value in cell E2 is, as a percentage of the mean in cell E11, using the formula =E2/E11. You accept the formula by pressing Ctrl+Enter and then double-click the fill handle downward. This time, you get into trouble! Ctrl+~ reveals the problem: The reference to E11 should be absolute; otherwise, the adjusted formula in the downward cells attempts to divide by empty cells, which is an invalid division-by-zero error.
Let's start over in cell F2:
1. Type the equals sign (=) in cell F2.
2. Press the Left Arrow key once to get to E2.
3. Type / (in order to divide).
4. Press the Left Arrow key once and then Ctrl+Down Arrow to get to E11.
5. Press F4 to make E11 absolute (that is, $E$11).
As a result, the copy behavior of the cell references is correct now: It is partly relative (E2) and partly absolute ($E$11). $ is a string sign that makes the column number and/or the row number absolute. F4 is a cycle key that works like this:
Pressing F4 once changes E11 to $E$11.
Pressing F4 twice changes E11 to E$11.
Pressing F4 three times changes E11 to $E11.
Pressing F4 four times takes changes the cell back to E11.
You select the range C14:F23 in order to calculate what the new concentration of a certain solution is if you dilute certain concentrations (in column B) with a particular factor (in row 13). Then you follow these steps:
1. Enter the formula =$B14*C$13 in cell C14.
2. While building the formula in the formula bar, select a cell and press F4 immediately. If you do this at a later stage, you need to click or double-click the cell address that needs to be changed before you press F4.
3. Accept this formula with Ctrl+Enter so it goes into all the selected cells, where it behaves partially as relative and partially as absolute.CHAPTER 4
A cell address is like a street number — and both can be difficult to remember. You might want to replace a cell number with a more meaningful address: a cell name. A cell name basically acts like an absolute cell address, but when used in formulas, it may be more informative. You can also name a range of cells. So you can have cell names and range names, but because a cell is basically also a range consisting of only one cell, the term range name is more comprehensive.
The top of Figure 1.7 shows a table with a list of readings that several analysts found during several tests. The bottom table marks each combination of a specific analyst and a specific test with a plus sign (+) if that reading was above the grand mean. Instead of comparing each individual reading with the grand mean in $G$12, you could also give cell G12 a more meaningful name — a range name. Here's how you do it:
1. Select cell G12.
2. In the Name box, to be found to the left of the formula bar, type GrandMean. Here are a few rules for naming:
Don't include spaces in a name, nor dots,@, #, /; underscores are okay.
Names are not case-sensitive, so GrandMean is the same as grandmean, GRANDMEAN, and so on.
Unique names function in the entire workbook. If you create a duplicate name, the second name will be assigned only to the specific sheet you are in.
3. Press Enter. If you don't, the name does not exist.
Now the name GrandMean has become official, so you can access the cell GrandMean through the drop-down list of the Name box — no matter where you are in this workbook — and Excel will take you there!
From now on, you should be able to call the IF function in cell B15. Its first argument is B2>GrandMean. You can just type the new range name, or you can click cell G12 to have Excel insert its name automatically.
Unfortunately, the previously installed range name does not kick in when you select multiple cells to fill them with the same formula. You must use an absolute cell address again, or you could use an extra tool: the Use in Formula drop-down located on the Formulas tab.
Try getting a copy of the grand mean in the cells G15:G24. When you just type the formula in the formula bar, notice that the name nicely pops up while you type =Gr ...
To find the range names listed, follow these steps:
1. Select the Formulas tab.
2. Click the Name Manager button.
3. Select the name of your choice.
4. Delete that name (using the button to the right) or expand/ change its reference (at the bottom).
Figure 1.8 shows that you can also name ranges of multiple cells. For example, you could name the first range Analysts, the second one Strains, and the third one Readings. Instead of doing all this manually, you can use a handy Excel tool:
1. Select the entire table by selecting A1, pressing Ctrl+Shift+Down Arrow, and then pressing Ctrl+Shift+Right Arrow.
2. From the Defined Names section of the Formulas tab, select Create Names from Selection.
3. Select Create Names from Values in [check] Top Row
4. Check the Name box to ensure that the three new names appear.
Now try counting in cell F2 how many readings Analyst1 has — by using the COUNTIF function: =COUNTIF (Analysts, E2). You can do something similar in cell G2 with the SUMIF function: =SUMIF(Analysts,E2,Readings). To find the Mean in cell H2, you need both previous columns — or you could use the Excel function AVERAGEIF. Then you can do something similar for the second table: =COUNTIF(Strains, E10) and =SUMIF (Strains, E10, Readings).
There is another interesting feature about names that you may benefit from. Instead of using a formula like =SUM (Readings), you can use the word Readings as it is displayed somewhere in a cell. However, you need the function INDIRECT to change the word into a name. For example, if cell A1 holds the word Readings, the formula =SUM (INDIRECT (A1)) would deliver the same results as =SUM (Readings). Why would you want to make such a detour? The answer is simple: Sometimes you want the headers of a summary table somewhere else in your book to be used in your formulas. One of the exercises at the end of this part offers an example of such a scenario.
Range names are great. However, the problem with range names is that a new row added at the end of a table, column, or row is not automatically incorporated into the range name — so formulas based on that range ignore the new entries. You can solve this problem by either inserting cells inside the range or manually fixing the range reference through the Name Manager. Neither solution is ideal.
Excerpted from Excel 2007 for Scientists by Gerard M. Verschuuren. Copyright © 2008 Dr. Gerard M. Verschuuren. Excerpted by permission of Holy Macro! Books.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.