In this chapter
Getting the Most from This Chapter 386
Entering Your First Formula 388
Three Methods of Entering Formulas 395
Entering the Same Formula in Many Cells 398
Copying a Formula by Using the Table Tool 402
Excel’s forte is performing calculations. When you use Excel, you typically use a combination of cells with numbers and cells with formulas. After you design a spreadsheet to calculate something, you can easily change the numbers used in the assumption cells and then watch Excel instantly calculate new results.
Don’t skip this entire chapter, because one particular trick in this chapter will save you daily frustration.
I regularly entertain accountants and auditors with my Power Excel program. While this program is a fun, laughter-filled tour through the inside tricks of Microsoft Excel, I do know that people are learning new things along the way.
I call them “gasp moments.”
Imagine this setting: I am in front of 200 managerial accountants—these are people who have Excel open 40 hours a week. You can generally figure that these folks are super-efficient with Excel. For any trick that I show, it might be already in the arsenal of half to three-quarters of the room. I will see a lot people nodding their heads and see an expression of surprise on a portion of the attendees.
Universally, though, there are a few tricks that get a universal gasp—perhaps 90% of the people never knew the trick and realize just how powerful it is. I thrive on the gasp moments.
I understand that everyone reading this book believes that they know Excel formulas. And, to a certain extent, this chapter is mostly a primer for the person who is new to Excel. However, even the most astute person using Excel should check out these sections of the chapter:
In Chapter 7, Table 7.1 shows a list of changed limits in Excel. A few of these limits relate specifically to formulas. For example, the number of characters in a formula increased from 1,024 to 8,192. The number of levels of nesting for IF functions increased from 7 to 64. Thanks to Excel 2007’s improved limits, you can calculate almost anything with a formula in Excel.
This chapter and Chapter 21, “Doing Cool Tricks with Formulas,” deal with formula basics. Chapters 22, “Understanding Functions,” through 27, “Using Math and Engineering Functions,” introduce adding functions to your formulas. Chapter 28, “Connecting Worksheets, Workbooks, and External Data,” introduces formulas that calculate data found on other worksheets or in other workbooks. Chapter 29, “Using Super Formulas in Excel,” provides interesting examples, such as 3D formulas and the all-powerful array formulas.
Note
The need to recalculate case studies at M.I.T. led Dan Bricklin to invent the first spreadsheet program, VisiCalc.
Because of the record-oriented nature of spreadsheets, you can generally build a formula once and then copy that formula to hundreds or thousands of cells without changing anything in the formula.
Tip From
Designing a formula that can be written once and then copied to a rectangular range of data is a fantastic way to make your use of Excel more efficient.
When looking at an Excel grid, you can’t tell the difference between a cell with a formula and one that contains numbers. To see if a cell contains a number or a formula, you select the cell. Look in the formula bar. If the formula bar contains a number, as shown in Figure 20.1, you know that it is a static value. As shown in Figure 20.2, if the formula bar contains a formula (most formulas start with =), you know that the number shown in the grid is the result of a formula calculation.
Your first formula was probably a SUM function, entered with the AutoSum button. However, for this discussion, I am talking about a pure mathematic formula that uses a value in a cell, added, subtracted, divided, or multiplied by a number or another cell.
There are billions of variations of formulas that can be used. Everyday life throws situations at you that can be solved with this type of formula. Keep these important points in mind as you start tinkering with your own formulas:
To illustrate these points, watch the steps to building a basic formula for a specific example.
In Figure 20.3, you want to enter a formula to calculate a target sales price. Cell B2 shows the product cost. In Column C, you want to calculate list price as two times the cost plus $3.
To enter a formula, follow these steps:
By default Excel usually moves the cell pointer down or to the right after you finish entering a formula. You should move the cell pointer back to Cell C2 to inspect the formula, as shown in Figure 20.3. Note that Excel shows a number in the grid, but the formula bar reveals the formula behind the number.
The formula =2*B2+3 really says “multiply two by the cell immediately to the left of me and add three.” If you need to put this formula in Cells C3 to C999, you do not need to re-enter the formula 996 times. You can simply copy the formula and paste it to all the cells. As you copy, Excel copies the essence of the formula: “Multiply two by the cell to the left of me and add three.” As you copy the formula to Cell C3, the formula becomes =2*B3+3. Excel handles all this automatically.
Excel’s ability to change B2 to B3 in the formula is called relative referencing. This is the default behavior of a reference. Sometimes, you do not want Excel to change a reference as the formula is copied, as explained in the next section.
Excel’s ability to change a formula as it is copied is what makes spreadsheets so useful. However, there are times when you need part of a formula to always point at one particular cell. This happens a lot when you have a setting at the top of the worksheet, such as a growth rate or a tax rate. It would be nice to change this cell once and have all of the formulas use the new rate.
The following example sets up a sample worksheet that exhibits this problem and shows you how to use an arcane notation style to easily solve the problem. When you see a reference with two dollar signs, for example $G$1, this indicates an absolute reference to G1.
Say that you have a sales tax factor in a single cell at the top of a worksheet. After you enter the formula =C2*G1, it accurately calculates the tax in Cell D2, as shown in Figure 20.5.
However, when you copy the same formula to Cell C3, you get a zero as the result. As you can see in Figure 20.6, Excel correctly changed Cell C2 to C3 in the copied formula. However, Excel also changed G1 to G2. Because there is nothing in G2, the calculation predicts a zero.
Because the sales tax factor is only in G1, you really want Excel to always point to G1. To make this happen, you need to build the original formula as =C2*$G$1. The two dollar signs tell Excel that you do not want to have the reference change as the formula is copied. The $ before the G freezes the reference to always point to Column G. The $ before the 1 freezes the reference to always point to Row 1. Now, when you copy this formula from Cell D2 to other cells in Column D, Excel changes the formula to =C3*$G$1.
To recap, a reference with two dollars signs is called an absolute reference.
In a number of situations, you might want to build a reference that has only one dollar sign. For example, in Figure 20.8, you want to use the monthly bonus rate in Row 3, but you want to allow the column to change. The formula for Cell C19 would be =C6*C$3.
When you copy this formula, it always points to the bonus amount in Row 3, but the remaining elements of the formula are relative. For example, the formula in D21 is =D8*D$3, which multiplies Jessica’s February sales by the February bonus rate.
There are two kinds of mixed references. One mixed reference freezes the row number and allows the column letter to change. The other mixed reference freezes the column letter, but allows the row number to change. No one has thought up clever names to distinguish between these references—they are both simply called mixed references.
As another example of the other kind of mixed reference, in Figure 20.9, you want a single formula to multiply the daily rate from Column A by the number of days in Row 4. This formula requires both kinds of mixed references.
In this case, you want the Cell A6 reference to always point to Column A, even as the formula is copied to the right. The A6 portion of the formula should therefore be entered as $A6. You also want the C5 portion of the formula to always point to Row 5, even as the formula is copied down the rows. The C5 portion of the formula should therefore be entered as C$5.
In the preceding section, you had to enter quite a few dollar signs in formulas. But you do not have to type the dollar signs! Immediately after entering a reference, you can press the F4 key to toggle the reference from a relative reference to an absolute reference that automatically has the dollar signs before the row and column. If you continue pressing F4, the reference toggles to a mixed reference with a dollar sign before the row number and then to a mixed reference with a dollar sign before the column letter. Pressing F4 again returns the reference to a relative reference. I find that it is easier to choose the right reference by looking at the various reference options offered by the F4 key.
The following sequence walks through how the F4 key works while you are entering a formula. This particular example was chosen because it requires two different types of mixed references.
The important concept is that you start pressing F4 after typing a cell reference but before you type a mathematical operator.
Note
After you press F4 again, Excel returns the reference to the relative state A6. As you continue to press F4, Excel toggles between the four modes. It is fine to toggle between them all and then choose the correct one. If you accidentally toggle past the $A6 version, you can just keep pressing F4 until the correct mode comes up again.
The F4 trick described in the preceding section works immediately after you enter a reference. If you try to change Cell A6 after you type the asterisk, pressing the F4 key has no effect.
You can still use F4 in this case, however. You simply click somewhere in the formula bar adjacent to the characters A6. Pressing F4 now adds dollar signs to that reference.
Some functions allow you to specify a rectangular range. For example, in Figure 20.16, you would like to enter a formula to calculate month-to-date sales. One formula in Cell C29 is =SUM(B2:B29). To be able to copy this formula, you need to change the formula to be =SUM(B$2:B29).
At the point in the figure, you might be tempted to press the F4 key. However, pressing F4 at this point would convert the reference to the fully absolute range $B$2:$B$29. Continuing to press F4 would toggle to B$2:B$29, then $B2:$B29, then B2:B29. Excel does not even attempt to go through the other 12 possible combinations of dollar signs in order to eventually offer B$2:B29.
In this case, you need to click the insertion point just before, just after, or in the middle of the characters B2 in the formula bar. If you then press F4, you toggle through the various dollar sign combinations, just on the B2 reference. Pressing F4 twice results in the proper combination, as shown in Figure 20.17.
In the examples in the previous sections, you entered a formula by typing it. Although you generally need to start a formula by typing the equals sign (or the plus sign), after that point, you have three options:
Assume that in Figure 20.18, you would like to multiply the merchandise total in Cell B2 by the sales tax rate in Cell F1.
If you started using computers after the advent of Microsoft Windows 3.1, it is likely that you use the mouse method for entering formulas. This method is intuitive, but it requires you to move your hand between the keyboard to the mouse several times, as in this example:
This method requires only four keystrokes, but it requires you to move to the mouse twice. Moving to the mouse is the slowest part of entering formulas, but this method is easier than typing the entire formula if you are not a touch typist.
The arrow key method is popular with people who started using spreadsheets in the days of Lotus 1-2-3 release 2.2. It is worthwhile to learn this method because it is incredibly fast. Almost all the formula entry can be accomplishing using keys on the right side of the keyboard. Here’s how it works:
Using this method requires 10 keystrokes, with no trips to the mouse. You can enter formulas that have no absolute references, mixed references, parentheses, or exponents by using just the arrow keys and the keys on the numeric keypad.
Tip From
Even if you are mouse-centric, you should try this method for half a day. When you get the feel for navigating by using the arrow keys, you can enter formulas much faster by using this method.
Note
Officially, every formula must start with an equals sign. However, to make former Lotus 1-2-3 users comfortable, Excel allows you to start a formula with a plus sign. Power Excel users have discovered that using a plus sign allows you to start a formula by typing on the numeric keypad. Because I routinely start formulas with the plus sign, I am often asked why I start with =+ instead of just =. Even though the formulas appear that way onscreen, I don’t actually enter the =. When a formula starts with a plus sign, Excel adds an equals sign and does not remove the plus sign, so you end up with a formula that looks like =+B2*$F$1.
So far in this chapter, you’ve entered a formula in one cell and then copied and pasted to get the formula in many cells. There are three alternate strategies:
This strategy works when you are entering formulas for a screen full or two of data:
If you want to enter a formula in one cell and then copy it to the other cells in a range, you can use the fill handle (that is, the square dot in the lower-right corner of the cell pointer). There are two ways to use the fill handle:
The dragging method works fine when you have less than one screen full of data:
This method is fine for copying a formula to a few cells. However, if you have thousands or hundreds of thousands of cells, it is annoying to drag to the last row. Invariably, as the scroll effect speeds up, you end up flying past the last row. In such a case, it is easier to copy a formula by double-clicking the fill handle.
In most datasets, double-clicking the fill handle is the fastest way to copy the formula. While you will love this method, you need to understand a few shortcomings that can hamper the method when an adjacent column has blank cells amongst the data.
Figure 20.25 shows a table that has hundreds of rows of data. You want to copy the formula from Cell C2 down to all the rows of data in Column B.
In this particular case, Cell B2 is nonblank, and Column B contains a value in every row down to the end of the data. This is the perfect condition for using the technique of double-clicking the fill handle. Follow these steps:
The active cell is copied down to the last row of your data, as shown in Figure 20.26.
The fill handle double-click method is fast. There are several arcane rules that can trip up the data, particularly if the column to the left contains a blank cell before the end of the data. Excel will be tricked into stopping the copy early because of this blank cell.
There are other rules. The fill handle can copy based on data in the adjacent column to the right or even data in the current column.
You should always type End and then the down arrow to make sure that the formula was copied far enough.
For a complete discussion of the arcane rules, see the Excel Troubleshooting section at the end of this chapter.
The table tool is a new feature in Excel 2007. When you use this tool, if you tell Excel that your current dataset is a table, Excel automatically copies new formulas down to the rest of the cells in the table.
Figure 20.27 shows an Excel worksheet that has headings at the top and many rows of data below the headings. Notice the blank Cell C15, which would normally trip up the fill handle double-click method.
To define a range as a table, select a cell within the dataset and type Ctrl+T or Ctrl+L. Excel uses its IntelliSense to guess the edges of the table. If its guess is correct, click OK in the Create Table dialog, as shown in Figure 20.28.
As shown in Figure 20.29, after Excel recognizes the range as a table, several changes occur:
If you now enter a formula in the table, Excel automatically copies that formula down to all rows of the table. The entire range, starting at D3 and extending downward, flashes black momentarily. This copy works even better than the fill handle double-click method because the copy is able to go past the blank cell in Row 15.
Note
As shown in Figure 20.30, there is a lightning bolt drop-down to the right of Cell D3. This drop-down offers you the opportunity to stop Excel from automatically copying the formula down.
18.223.149.223