Successfully reported this slideshow.
Upcoming SlideShare
×

# MS Excel - Name range

10 views

Published on

Learn how to name groups of cells in Microsoft Excel. Commonly called Range Names, named cells in Excel can greatly simplify the programming of Excel worksheets/ workbooks with formulas.

Published in: Education
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

### MS Excel - Name range

1. 1. 1 C H A P T E R 1 range names Ques ions answe ed in is c a e : I want the total sales in Arizona, California, Montana, New York, and New Jersey. Can I use a formula to compute the total sales in a form such as AZ+CA+MT+NY+NJ instead of SUM(A21:A25) and still get the right answer? What does a formula such as Average(A:A) do? What is the difference between a name with workbook scope and one with worksheet scope? I really am getting to like range names. I have started de ning range names for many of the workbooks I have developed at the of ce. However, the range names do not show up in my formulas. How can I make recently created range names show up in previously created formulas? How can I paste a list of all range names (and the cells they represent) into my worksheet? I am computing projected annual revenues as a multiple of last year’s revenue. Is there a way to have the formula look like (1+growth)*last year? For each day of the week, we are given the hourly wage and hours worked. Can we compute total salary for each day with the wages*hours formula? You have probably worked with worksheets that use formulas such as SUM(A5000:A5049). Then you have to nd out what’s contained in cells A5000:A5049. If cells A5000:A5049 contain sales in each US state, wouldn’t the formula SUM(USSales) be easier to understand? In this chapter, you learn how to name individual cells or ranges of cells and how to use range names in formulas. How can I create named ranges? There are three ways to create named ranges: By entering a range name in the Name box By clicking Create From Selection in the De ned Names group on the Formulas tab By clicking Name Manager or De ne Name in the De ned Names group on the Formulas tab
2. 2. 2 CHAPTER 1 Range names Using e Name box o c ea e a ange name The Name box (shown in Figure 1-1) is located directly above the label for column A. (To see the Name box, click the Formula bar.) To create a range name in the Name box, simply select the cell or range of cells that you want to name, click in the Name box, and then type the range name you want to use. Press Enter, and you’ve created the range name. Clicking the drop-down arrow in the Name box displays the range names de ned in the current workbook. You can display all the range names in a workbook by pressing the F3 key to open the Paste Name dialog box. When you select a range name from the Name box, Microsoft Excel 2013 selects the cells corresponding to that range name. This enables you to verify that you’ve chosen the cell or range that you intended to name. Range names are not case sensitive. FIGURE 1-1 You can create a range name by selecting the cell range you want to name and then typing the range name in the Name box. For example, suppose you want to name cell F3 east and cell F4 west. See Figure 1-2 and the Eastwestempt.xlsx le. Select cell F3, type east in the Name box, and then press Enter. Select cell F4, type west in the Name box, and press Enter. If you now reference cell F3 in another cell, you see =east instead of =F3. This means that whenever you see the reference east in a formula, Excel will insert whatever is in cell F3. FIGURE 1-2 Name cell F3 east and cell F4 west. Suppose you want to assign a rectangular range of cells (such as A1:B4) the name Data. Select the cell range A1:B4, type Data in the Name box, and press Enter. Now a formula such as =AVERAGE(Data) would average the contents of cells A1:B4. See the Data.xlsx le and Figure 1-3.
3. 3. Range names CHAPTER 1 3 FIGURE 1-3 Name the A1:B4 range Data. Sometimes, you want to name a range of cells made up of several noncontiguous rectangular ranges. For example, in Figure 1-4 and the Noncontig.xlsx le, you might want to assign the name Noncontig to the range consisting of cells B3:C4, E6:G7, and B10:C10. To assign this name, select any one of the three rectangles making up the range (B3:C4 for now). Hold down the Ctrl key and then select the other two ranges (E6:G7 and B10:C10). Now release the Ctrl key, type the name Noncontig in the Name box, and press Enter. Using Noncontig in any formula will now refer to the contents of cells B3:C4, E6:G7, and B10:C10. For example, entering the formula =AVERAGE(Noncontig) in cell E11 yields 4.75 (because the 12 numbers in your range add up to 57, and 57/12 = 4.75). FIGURE 1-4 This is how to name a noncontiguous range of cells.
4. 4. 4 CHAPTER 1 Range names C ea ing named anges by using C ea e F om Selec ion The Statestemp.xlsx worksheet contains sales during March for each of the 50 US states. Figure 1-5 shows a subset of this data. You would like to name each cell in the B6:B55 range with the cor- rect state abbreviation. To do this, select the A6:B55 range and click Create From Selection in the De ned Names group on the Formulas tab (see Figure 1-6) and then select the Left Column check box, as indicated in Figure 1-7. FIGURE 1-5 By naming the cells that contain state sales with state abbreviations, you can use the abbreviation rather than the cell’s column letter and row number when you refer to the cell. FIGURE 1-6 Select Create From Selection.
5. 5. Range names CHAPTER 1 5 FIGURE 1-7 Select the Left Column check box. Excel now knows to associate the names in the rst column of the selected range with the cells in the second column of the selected range. Thus, B6 is assigned the range name AL, B7 is named AK, and so on. Creating these range names in the Name box would have been incredibly tedious! Click the drop-down arrow in the Name box to verify that these range names have been created. Creating range names by using De ne Name If you choose Name Manager on the Formulas tab and select De ne Name from the menu shown in Figure 1-6, the New Name dialog box shown in Figure 1-8 opens. FIGURE 1-8 This is how the New Name dialog box appears before creating any range names.
6. 6. 6 CHAPTER 1 Range names Suppose you want to assign the name range1 (range names are not case sensitive) to the cell range A2:B7. Type range1 in the Name box and then point to the range or type =A2:B7 in the Refers To area. The New Name dialog box will now look like Figure 1-9. Click OK, and you’re done. FIGURE 1-9 The New Name dialog box looks like this after creating a range name. If you click the Scope arrow, you can select Workbook or any worksheet in your workbook. This decision is discussed later in this chapter, so for now, just choose the default scope of Workbook. You can also add comments for any of your range names. Name Manage If you now click the Name arrow, the name range1 (and any other ranges you have created) appears in the Name box. In Excel 2013, there is an easy way to edit or delete your range names. Open Name Manager by selecting the Formulas tab and then click Name Manager from the menu shown in Figure 1-6. You now see a list of all range names. For example, for the States.xlsx le, the Name Manager dialog box will look like Figure 1-10. To edit any range name, double-click the range name or select the range name and click Edit; you can then change the name of the range, the cells the range refers to, or the scope of the range. To delete any subset of range names, rst select the range names you want to delete. If the range names are listed consecutively, select the rst range name in the group you want to delete, hold down the Shift key, and select the last range name in the group. If the range names are not listed consecutively, you can select any range name you want to delete and then hold down the Ctrl key while you select the other range names for deletion. Then press the Delete key to delete the selected range names. Now look at some speci c examples of how to use range names.
7. 7. Range names CHAPTER 1 7 FIGURE 1-10 This is the Name Manager dialog box for States.xlsx. Answers to this chapter’s questions This section provides the answers to the questions that are listed at the beginning of the chapter. I want the total sales in Arizona, California, Montana, New York, and New Jersey. Can I use a formula to compute the total sales in a form such as AZ+CA+MT+NY+NJ instead of SUM(A21:A25) and still get the right answer? Return to the States.xlsx le, in which you assigned each state’s abbreviation as the range name for the state’s sales. If you want to compute total sales in Alabama, Alaska, Arizona, and Arkansas, clearly you could use the formula SUM(B6:B9). You could also point to cells B6, B7, B8, and B9, and the for- mula would be entered as =AL+AK+AZ+AR. The latter formula is self-describing. As another illustration of how to use range names, look at the Historicalinvesttemp.xlsx le, shown in Figure 1-11, which contains annual percentage returns on stocks, T-bills, and bonds. (Some rows are hidden in this gure; the data ends in row 89.)
8. 8. 8 CHAPTER 1 Range names FIGURE 1-11 This gure shows historical investment data. Select the B8:D89 cell range and then choose Formulas and Create From Selection. For this example, names are created in the top row of the range. The B8:B89 range is named Stocks, the C8:C89 range T.Bills, and the D8:D89 range T.Bonds. Now you no longer need to remember where your data is. For example, in cell B91, after typing =AVERAGE(, you can press F3, and the Paste Name dialog box opens, as shown in Figure 1-12. You can also bring up a list of range names that can be pasted in formulas if you start typing and click Use In Formula on the Formulas tab. FIGURE 1-12 You can add a range name to a formula by using the Paste Name dialog box.
9. 9. Range names CHAPTER 1 9 You can select Stocks in the Paste Name list and click OK. After entering the closing parenthesis, the formula, =AVERAGE(Stocks), computes the average return on stocks (11.28 percent). The beauty of this approach is that even if you don’t remember where the data is, you can work with the stock return data anywhere in the workbook! This chapter would be remiss if it did not mention the exciting AutoComplete capabilities of Excel 2013. If you begin typing =Average(T, Excel shows you a list of range names and functions that begin with T, and you can just double-click T.Bills to complete the entry of the range name. What does a formula such as Average(A:A) do? If you use a column name (in the form of A:A, C:C, and so on) in a formula, Excel treats an entire column as a named range. For example, entering the =AVERAGE(A:A) formula averages all numbers in column A. Using a range name for an entire column is very helpful if you frequently enter new data in a column. For example, if column A contains monthly sales of a product, as new sales data are entered each month, your formula computes an up-to-date monthly sales average. Use caution, however, because if you enter the =AVERAGE(A:A) formula in column A, you will get a circular reference mes- sage because the value of the cell containing the average formula depends on the cell containing the average. You learn how to resolve circular references in Chapter 10, “Circular references.” Similarly, entering the =AVERAGE(1:1) formula averages all numbers in row 1. What is the difference between a name with workbook scope and one with worksheet scope? The Sheetnames.xlsx le will help you understand the difference between range names that have workbook scope and range names that have worksheet scope. When you create names with the Name box, the names default to workbook scope. For example, suppose you use the Name box to assign the name sales to the cell range E4:E6 in Sheet3, and these cells contain the numbers 1, 2, and 4, respectively. If you enter a formula such as =SUM(sales) in any worksheet, you obtain an answer of 7 because the Name box creates names with workbook scope, so anywhere in the workbook you refer to the name sales (which has workbook scope), the name refers to cells E4:E6 of Sheet3. In any worksheet, if you now enter the =SUM(sales) formula, you will obtain 7 because anywhere in the workbook, Excel links sales to cells E4:E6 of Sheet3. Now suppose that you type 4, 5, and 6 in cells E4:E6 of Sheet1 and 3, 4, and 5 in cells E4:E6 of Sheet2, and then you open Name Manager, give the name jam to cells E4:E6 of Sheet1, and de ne the scope of this name as Sheet1. Then you move to Sheet2, open Name Manager, give the name jam to cells E4:E6, and de ne the scope of this name as Sheet2. The Name Manager dialog box now looks like Figure 1-13.
10. 10. 10 CHAPTER 1 Range names FIGURE 1-13 The Name Manager dialog box displays worksheet and workbook names. Now, what if you enter the =SUM(jam) formula in each sheet? In Sheet 1, =SUM(jam) will total cells E4:E6 of Sheet1. Because those cells contain 4, 5, and 6, you obtain 15. In Sheet2, =SUM(jam) will total cells E4:E6 of Sheet2, yielding 3 + 4 + 5 = 12. In Sheet3, however, the =SUM(jam) formula will yield a #NAME? error because no range is named jam in Sheet3. If you enter the =SUM(Sheet2!jam) formula anywhere in Sheet3, Excel will recognize the worksheet-level name that represents cell range E4:E6 of Sheet2 and yield a result of 3 + 4 + 5 = 12. Thus, by prefacing a worksheet-level name by its sheet name followed by an exclamation point (!), you can refer to a worksheet-level range in a worksheet other than the sheet in which the range is de ned. I really am getting to like range names. I have started de ning range names for many of the workbooks I have developed at the of ce. However, the range names do not show up in my formulas. How can I make recently created range names show up in previously created formulas? Look at the Applynames.xlsx le and Figure 1-14.
11. 11. Range names CHAPTER 1 11 FIGURE 1-14 This gure shows how to apply range names to formulas. The price of a product was entered in cell F3 and product demand of =10000–300*F3 in cell F4. The unit cost and xed cost are entered in cells F5 and F6, respectively, and pro t is computed in cell F7 with the =F4*(F3–F5)–F6 formula. In this example, Formulas, Create From Selection, and then Left Column are used to name cell F3 price, cell F4 demand, cell F5 unit cost, cell F6 xed cost, and cell F7 pro t. You would like these range names to show up in the cell F4 and cell F7 formulas. To apply the range names, rst select the range where you want the range names applied (in this case, F4:F7). Now open the De ned Names group on the Formulas tab, click the De ne Name arrow, and then choose Apply Names. Highlight the names you want to apply and then click OK. Note that cell F4 now contains the =10000–300*price formula, and cell F7 contains the =demand*(price–unit_cost)– xed_cost formula, as you wanted. By the way, if you want the range names to apply to the entire worksheet, select the entire work- sheet by clicking the Select All button at the intersection of the column and row headings. How can I paste a list of all range names (and the cells they represent) into my worksheet? Press F3 to open the Paste Name box and then click the Paste List button. (See Figure 1-12.) A list of range names and the cells each corresponds to will be pasted into your worksheet, beginning at the current cell location. I am computing projected annual revenues as a multiple of last year’s revenue. Is there a way to have the formula look like (1+growth)*last year? The Last year.xlsx le contains the solution to this problem. As shown in Figure 1-15, you want to com- pute revenues for 2012–2018 that grow at 10 percent per year off a base level of \$300 million in 2011.
12. 12. 12 CHAPTER 1 Range names FIGURE 1-15 Create a range name for the previous year. To begin, use the Name box to name cell B3 growth. Now comes the good part! Move the cursor to B7 and open the New Name dialog box by clicking De ne Name in the De ned Names group on the Formulas tab. Fill in the New Name dialog box as shown in Figure 1-16. FIGURE 1-16 In any cell, this name refers to the cell above the active cell. Because you are in cell B7, Excel interprets this range name always to refer to the cell above the current cell. This would not work if, in the B6 cell reference, the 6 were dollar signed because dollar signing the 6 would prevent the row reference from changing to pick up the row directly above the active cell. If you enter the =previous*(1+growth) formula in cell B7 and copy it down to the B8:B13
13. 13. Range names CHAPTER 1 13 range, each cell will contain the formula you want and will multiply 1.1 by the contents of the cell directly above the active cell. For each day of the week, we are given the hourly wage and hours worked. Can we compute total salary for each day with the wages*hours formula? As shown in Figure 1-17 (see the Namedrows.xlsx le), row 12 contains daily wage rates, and row 13 contains hours worked each day. FIGURE 1-17 In any cell, this name refers to the cell above the active cell. You can select row 12 (by clicking the 12) and use the Name box to enter the name wage. Select row 13 and type the name hours in the Name box. If you now enter the wage*hours formula in cell F14 and copy this formula to the G14:L14 range, you can see that Excel nds the wage and hour val- ues and multiplies them in each column. Remarks Excel does not allow you to use the letters r and c as range names. The only symbols allowed in range names are periods (.) and underscores (_). If you use Create From Selection to create a range name, and your name contains spaces, Excel inserts an underscore (_) to ll in the spaces. For example, Product 1 is created as Product_1. Range names cannot begin with numbers or look like a cell reference. For example, 3Q and A4 are not allowed as range names. Because Excel 2013 has more than 16,000 columns, a range name such as cat1 is not permitted because there is a CAT1 cell. If you try to name a cell CAT1, Excel tells you the name is invalid. Probably your best alternative is to name the cell cat1_. Problems 1. The Stock.xlsx le contains monthly stock returns for General Motors and Microsoft. Name the ranges containing the monthly returns for each stock and compute the average monthly return on each stock. 2. Open a new blank workbook and name the range containing the A1:B3 and A6:B8 cells as Red.
14. 14. 14 CHAPTER 1 Range names 3. In cells Q5 and Q6 in the Citydistances.xlsx le, you can enter the latitude and longitude of any city and, in Q7 and Q8, the latitude and longitude of a second city. Cell Q10 computes the distance between the two cities. De ne range names for the latitude and longitude of each city and ensure that these names show up in the formula for total distance. 4. The Sharedata.xlsx le contains the numbers of shares you own of each stock and the price of each stock. Compute the value of the shares of each stock with the shares*price formula. 5. Create a range name that averages the past ve years of sales data. Assume annual sales are listed in a single column. Use data in the Last5.xlsx le.