|
Chapter 3: Performing Calculations
In this chapter, you create a calculation area and explore some of Excel's functions, including the decision-making IF function. You use formulas to link worksheets, and finally, you print your worksheet and publish it as a Web page. If you don't work in sales, you can adapt the techniques covered in this chapter to analyze other sources of income, such as service fees, subscriptions, or donations. Chapters 1 and 2 covered some Excel basics, and you now know enough to create simple tables. But you are missing the essential piece of information that turns a table into a worksheet: how to enter formulas. The whole purpose of building worksheets is to have Excel perform calculations for you. In this chapter, we show you how to enter formulas in the 1999 Sales workbook so that you can analyze sales. Along the way, we cover some powerful techniques for manipulating data and a few principles of worksheet design. So fire up Excel, and then we'll get started. Simple CalculationsExcel has many powerful functions that are a sort of shorthand for the various formulas used in mathematical, logical, statistical, financial, trigonometric, logarithmic, and other types of calculations. However, the majority of worksheets created with Excel involve simple arithmetic. In this section, we show you how to use four arithmetic operators (+, -, *, and /) to add, subtract, multiply, and divide, and then we introduce two Excel features with which you can quickly add sets of numeric values. Doing ArithmeticIn Excel, you begin a formula with an equal sign (=). In the simplest formulas, the equal sign is followed by a set of values separated by +, -, *, or /, such as =5+3+2 If you enter this formula in any blank cell in a worksheet, Excel displays the result 10. Let's experiment with formulas in the 1999 Sales workbook. You want most of the calculations and formatting you do in this chapter to take effect in all the quarter worksheets, so you'll start by grouping them and inserting a couple of blank rows to give you space to work:
Now you're ready to construct a formula in cell B5, using some of the values in the Amount of Sale column. You tell Excel to use a value simply by clicking the cell that contains it. Follow these steps:
Totaling Columns of ValuesAlthough this method of creating a formula is simple enough, it would become tedious if you had to type and click in order to add a long series of values. Fortunately, Excel automates the addition process with a very useful button: the AutoSum button.
Using the AutoSum Button The AutoSum button will probably become one of your most often-used Excel buttons. In fact, using this button is so easy that we'll dispense with explanations and simply show you what to do:
Displaying formulas By default, Excel displays the results of formulas in cells, not their underlying formulas. To see the actual underlying formulas in the worksheet, choose Options from the Tools menu, display the View tab, select Formulas in the Window Options section, and click OK. Excel widens the cells so that you can see the formulas. To redisplay the results, simply deselect the Formulas option.
Using the SUM Function Let's go back and dissect the SUM function that Excel inserted in cell E19 when you clicked the AutoSum button so that you can examine the function's components. With cell E19 selected, you can see the following entry in the formula bar: =SUM(E7:E18) Like all formulas, the SUM function begins with an equal sign (=). Next comes the function name in capital letters, followed by a set of parentheses enclosing the reference to the range containing the amounts you want to total. This reference is the SUM function's argument. An argument answers questions such as "What?" or "How?" and gives Excel the additional information it needs to perform the function. In the case of SUM, Excel needs only one piece of informationthe references of the cells you want to total. As you'll see later, Excel might need several pieces of information to carry out other functions, and you enter an argument for each piece. Creating a SUM function from scratch is not particularly difficult. For practice, follow these steps:
Referencing Formula Cells in Other FormulasAfter you create a formula in one cell, you can use its result in other formulas simply by referencing its cell. To see how this works, follow these steps:
Function names When you type a function name, such as SUM, in the formula bar, you don't have to type it in capital letters. Excel capitalizes the function name for you when you complete the entry. If Excel does not respond in this way, you have probably entered the function name incorrectly. Naming Cells and RangesMany of the calculations that you might want to perform on this worksheetfor example, calculating each sales amount as a percentage of total saleswill use the total you have calculated in cell B5. You could include a copy of the SUM function now in cell B5 in these other calculations, or you could simply reference cell B5. The latter method seems quick and simple, but what if you subsequently move the formula in B5 to another location? Excel gives you a way to reference this formula no matter where on the worksheet you move it. You can assign cell B5 a name and then use the name in any calculations that involve the total. Here's how to assign a name to a cell:
To see how Excel uses the names you assign, try this:
You can also assign names to ranges. Let's use a different method to assign the name Amount to the cells containing amounts in column E:
Excel's name suggestions When you choose Name and then Define from the Insert menu to name a cell or a range of cells, Excel looks above and to the left of the selected cell or range to find a name. Keep this information in mind when you enter labels in your worksheet. If you plan on defining names for certain cells, enter a label above or to the left of the cell(s) that Excel can readily use as a name.
Now let's replace the range reference in the SUM function in cell B5 with the new range name. (You can't do this while the worksheets are grouped.) Follow these steps:
From now on, we won't give you specific instructions to save your work, but you should get in the habit of saving often, perhaps after working through each example. Name conventions Certain rules apply when you name cells or ranges. Although you can use a number within the name, you must start the name with a letter, an underscore, or a backslash. Spaces are not allowed within the name, so you should use underscore characters to rep- resent spaces. For example, you cannot use 1999 as a name, but you can use Totals_1999. Creating a Calculation AreaBefore we discuss other calculations you might want to perform with this worksheet, let's look at ways to format your information to make the results of calculations stand out from the data. As your worksheets grow in complexity, you'll find that paying attention to such details will keep you oriented and help others understand your results. Usually when you create a worksheet, you are interested not so much in the individual pieces of information as in the results of the calculations you perform on the pieces. The current worksheet is not much bigger than one screen, but often worksheets of this type include many screenfuls of information. It's a good idea to design your worksheets so that the important information is easily accessible and in a predictable location. For these reasons, we suggest that you leave room in the top left corner of your worksheets for a calculation area. This habit is useful for the following reasons:
Jumping to named cells To move quickly to a named cell, press the F5 key. When Excel displays the Go To dialog box, select the name of the cell you want to move to and click OK.
To see firsthand how helpful this can be, create an area at the top of each of the grouped quarter sheets of the 1999 Sales workbook for a set of calculations. Start by freeing up some more space below the worksheet title:
Page breaks If you want to print the calculation area on one page and the supporting data on another, or if you need to control where the pages break in a multipage worksheet, select the cell below the row and to the right of the column at which you want Excel to break the page, and choose Page Break from the Insert menu. Excel indicates the break by using a dashed line. To remove a manual page break, select the cell immediately below and to the right of the page break, and choose Remove Page Break from the Insert menu. To remove all the page breaks in a worksheet, select the entire document by clicking the square in the top left corner of the worksheet (at the intersection of the row and column headers), and choose Remove Page Break. Now you need to make the calculation area stand out. With Excel, you can get really fancy, using colored fonts and shading to draw attention to calculation results. For now, though, let's place a simple border around the calculation area:
Buttons for borders and shading To add a border around a selected cell or range, click the arrow to the right of the Borders button on the Formatting toolbar to display a palette of options (including bor- ders on the left, right, top, or all sides). Then click the button that adds the border you want. To fill a selected cell or range with a color, click the arrow to the right of the Fill Color button on the Formatting toolbar. When Excel displays a palette of colors, click the one you want. (The palettes include a No Borders button and a No Fill button, which you can use to remove borders and shading from selections.)
Now let's add another touch:
More CalculationsLet's perform some more calculations on the sales data, starting with the average sale. Averaging ValuesTo find the average of the invoices in this worksheet, you can build a formula that includes Excel's AVERAGE function. To avoid making errors while typing function names and to make sure you include all the arguments needed for the calculation, you'll want to use the Paste Function button. Follow these steps:
Conditional formatting To monitor a worksheet, you can use conditional formatting to highlight a cell that meets certain criteria. For example, you can display a cell's value in magenta if it is over 200,000. To apply this type of formatting, select the cell and choose Conditional Formatting from the Format menu. Select a condition from the second drop- down list and enter conditional parameters in the appropriate edit boxes. Then click Format, select the formatting to be used to highlight the cell, and click OK twice. When the value in the selected cell meets the condition you've set, Excel highlights the cell with the specified formatting. If you want to delete conditional formatting, select the cell, choose Conditional Formatting from the Format menu, click Delete, select the condition, and click OK twice. Identifying Highest and Lowest ValuesExcel provides two functions that instantly identify the highest and lowest values in a group. To understand the benefits of these functions, imagine that the 1st Quarter worksheet contains data from not 12 but 112 customers! Let's start with the highest sale:
Moving dialog boxes To enter a cell or range reference in a dialog box,dialog boxes;movingmoving;dialog boxes you can click the cell or select the range in the worksheet. If the dialog box obscures the desired cell or range, simply move the dialog box out of the way by pointing to its title bar, holding down the mouse button, and dragging until you can see the part of the worksheet you're interested in. Many dialog boxes also contain Collapse buttons (the buttons with the red arrow) that shrink the dialog box so that you can view more of the worksheet.
To determine the lowest sale, you'll use Excel's AutoCalculate feature:
Calculating with NamesThe salespeople at the Cream of the Crop ice cream company all earn commission. As a gross indicator of sales expenses, you can use the Total Sales value in cell B5 to calculate the total sales commission. Here's how:
A function for every task Excel provides many functions for common business and financial taskssome of them quite complex. To get more information about a function, first display the Help window, and then type worksheet_function on the Index tab and click Search. In the Choose A Topic list, click a specific function (for example, RATE). Excel then displays a description of the function, its syntax, and any other information that is pertinent in the pane on the right. Formulas That Make DecisionsThere will be times when you want Excel to carry out one task under certain circumstances and another task if those circumstances don't apply. To give this kind of instruction to Excel, you use the IF function. Logical operators Here is a list of operators you can use with the IF function: =<><>>=<= You can also use AND and OR to combine two or more tests. The function =IF(AND(B4=0,B5>0),"Yes","No") displays Yes only if both tests are true. The function =IF(OR(B4=0,B5>0),"Yes","No") displays Yes if either test is true. In its simplest form, the IF function tests the value of a cell and does one thing if the test is positive (true) and another if the test is negative (false). It requires three arguments: the test, the action to perform if the test is true, and the action to perform if the test is false. You supply the arguments one after the other within the function's parentheses, separating them with commas (no spaces). Try this:
In this example, the test Excel performed was a simple evaluation of the value in a cell. However, you can also build tests that involve other functions. Recall that the last two characters of the customer numbers in column C of the worksheet indicate whether the sale was made to a large chain store or to an individually owned store. Suppose you want to assign each customer number to a Chain or Individual category so that you can compare the sales for the two store types. Follow these steps:
You have told Excel to look at the two characters at the right end of the value in cell C14 and if they are AA, to enter Chain in cell D14. If they are not AA, Excel is to enter Individual. The result is shown here: The Range Finder When you double-click a cell to edit a formula, Excel's Range Finder feature displays any of the formula's cells or ranges of cells in a particular color and places a matching color border around the actual cell or range. The Range Finder is a useful means of double-checking the references in your formulas. Copying FormulasThe IF function you just entered is arduous to type, even for good typists. Fortunately, you don't have to enter it more than once. By using a simple mouse operation called AutoFill, you can copy the formula into the cells below, like this:
When you used AutoFill, Excel changed the reference so that it refers to cell C15 as its argument, not C14. Why? By default, Excel uses relative references in its formulas. Relative references refer to cells by their position in relation to the cell containing the formula. So when you copied the formula in cell D14 to cell D15, Excel changed the reference from C14 to C15the cell in the same row and one column to the left of the cell containing the formula. If you were to copy the formula in cell D14 to F14, Excel would change the reference from C14 to E14 so that the formula would continue to reference the cell in the same relative position. When you don't want a reference to be copied as a relative reference, as it was in these examples, you need to use an absolute reference. Absolute references refer to cells by their fixed position in the worksheet. To make a reference absolute, you add dollar signs before its column letter and row number. For example, to change the reference C4:C9 to an absolute reference, you would enter it as $C$4:$C$9. You could then copy a formula that contained this reference anywhere on the worksheet and it would always refer to the range C4:C9. References can also be partially relative and partially absolute. For example, $C4 has an absolute column reference and a relative row reference, and C$4 has a relative column reference and an absolute row reference. Linking Worksheets with FormulasEarlier you transferred the results of a SUM function to a different cell simply by referencing the cell containing the function (see page 62). You can just as easily transfer a function's results from one worksheet to another, thereby linking the two worksheets so that any changes in the source worksheet are immediately reflected in the linked worksheet. In this section, you'll set up the four quarter worksheets first so that they contain different sets of invoice data, and then you'll use the Totals worksheet to build some summary information. Let's get going:
Text values as arguments When entering text values as arguments in a formula, you must enclose them in quotation marks. Otherwise, Excel thinks the text is a name and displays the error value #NAME? in the cell. For example, =RIGHT("Excel",2) gives the value "el," but =RIGHT(Excel,2) results in an errorunless the range name Excel happens to be assigned to a cell or range in the worksheet. Why haven't the values in the calculation area changed? The formulas in B5:B10 reference the Amount and Total names, which you applied to cells on the 1st Quarter sheet. Follow these steps to quickly create new names:
The Fill command You can use the Fill command to copy entries into a range of adjacent cells. Select the cell whose contents and formats you want to copy, drag through the adjacent range, and choose Fill from the Edit menu. How Excel copies the cell is determined by the shape of the selection and the command you choose from the Fill submenu. For example, selecting cells below an entry and choosing Down copies the entry down a range; selecting cells to the right of an entry and choosing Right copies the entry to the right; and so on. Three related commands are also available on this submenu: Across Worksheets copies entries to the equivalent cells in a group of selected worksheets (to select the worksheets, hold down Ctrl and click each sheet's tab); Series fills the selection with a series of values or dates; and Justify distributes the contents of the active cell evenly in the cells of the selected range.
Now that the quarter sheets contain different sets of data, you can turn your attention to the Totals worksheet:
Now test the links by following these steps:
More about AutoFill You can copy information from one area of your worksheet to an- other using two methods: Auto- Fill, and copy and paste. These methods produce similar results unless the entry you are copying contains a number that can be incremented, such as in the 1st Quarter heading, or the cell con- tains an entry from a custom list. If the cell contains a number that can be incremented, using Auto- Fill copies the entry and incre- ments the numberfor example, 1st Quarter becomes 2nd Quarter, 3rd Quarter, and so on. If the cell contains an entry from a custom list, Excel fills the cells with other entries from that list. You define a custom list by choosing Options from the Tools menu, clicking the Custom Lists tab, selecting NEW LIST in the Custom Lists box, and typing the list's entries in the List Entries box. (You can also click an insertion point in the Import List From Cells edit box, select a range containing the entries, and click the Import button to import the entries as a list.) After you click OK, you can enter the list in consecutive cells of any worksheet by typing one of the entries and dragging the fill handle. This fea- ture is invaluable if you frequently create worksheets involving lists of the same entries, such as part numbers or employee names.
Next Visit Microsoft Press for more information on Quick Course in Microsoft Excel
Last Updated: Friday, July 6, 2001 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||