You are on page 1of 11

Chapter 2

Range Names
Questions answered in this chapter:
■ I want to total sales in Arizona, California, Montana, New York, and New Jersey. Can I
use a formula to compute 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 like 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 defining range names for many
of the workbooks I have developed at the office. 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 formula wages*hours?
You have probably worked with worksheets that use formulas such as SUM(A5000:A5049).
Then you have to find out what’s contained in cells A5000:A5049. If cells A5000:A5049
contain sales in each U.S. state, wouldn’t the formula SUM(USSales) be easier to understand?
In this chapter, I’ll teach you how to name individual cells or ranges of cells. I’ll also show you
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 Defined Names group on the Formulas tab.
■ By clicking Name Manager or Define Name in the Defined Names group on the
Formulas tab.

9
10 Microsoft Excel 2010: Data Analysis and Business Modeling

Using the Name Box to Create a Range Name


The Name box (shown in Figure 2-1) is located directly above the label for column A. (To see
the Name box, you need to display 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 Name arrow displays the range names defined 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 2010 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 2-1 You can create a range name by se ect ng the ce range you want to name and then typ ng the
range name n the Name box.

For example, suppose you want to name cell F3 east and cell F4 west. See Figure 2-2 and the
file Eastwest.xlsx. Simply select cell F3, type east in the Name box, and then press Enter. Then
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 2-2 Nam ng ce F3 east and ce F4 west.

Suppose you want to assign a rectangular range of cells (such as A1:B4) the name Data.
Simply 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 file
Data.xlsx and Figure 2-3.

FIGURE 2-3 Nam ng range A1:B4 Data.


Chapter 2 Range Names 11

Sometimes you want to name a range of cells made up of several noncontiguous rectangular
ranges. For example, in Figure 2-4 and the file Noncontig.xlsx, we 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 (I chose B3:C4). 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, enter-
ing the formula AVERAGE(Noncontig) in cell E10 yields 4.75 (because the 12 numbers in our
range add up to 57 and 57/12 4.75).

FIGURE 2-4 Nam ng a noncont guous range of ce s.

Creating Named Ranges by Using the Create From Selection


Option
The worksheet States.xlsx contains sales during March for each of the 50 U.S. states.
Figure 2-5 shows a subset of this data. We would like to name each cell in the range B6:B55
with the correct state abbreviation. To do this, select the range A6:B55, and click Create From
Selection in the Defined Names group on the Formulas tab (see Figure 2-6). Then select the
Left Column check box, as indicated in Figure 2-7.

FIGURE 2-5 By nam ng the ce s that conta n state sa es w th state abbrev at ons, you can use the abbrev at on
rather than the ce s co umn etter and row number when you refer to the ce .
12 Microsoft Excel 2010: Data Analysis and Business Modeling

FIGURE 2-6 Se ect Create From Se ect on.

FIGURE 2-7 Se ect the Left Co umn check box.

Excel now knows to associate the names in the first 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. Note that creating these range names in the Name box would have
been incredibly tedious! Click the Name arrow to verify that these range names have been
created.

Creating Range Names by Using the Name Manager Option


If you click Name Manager on the Formulas tab and then choose New, the New Name dialog
box shown in Figure 2-8 opens.

FIGURE 2-8 The New Name d a og box before creat ng any range names.

Suppose you want to assign the name range1 (range names are not case sensitive) to the
cell range A2:B7. Simply 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 2-9. Click
OK, and you’re done.
Chapter 2 Range Names 13

FIGURE 2-9 New Name d a og box after creat ng a range name.

If you click the Scope arrow, you can select the option Workbook or any worksheet in
your workbook. I’ll discuss this decision later, so for now just choose the default scope of
Workbook. You can also add comments for any of your range names.

The Name Manager


If you now click the Name arrow, the name range1 (and any other ranges you have created)
appears in the Name box. In Excel 2010, there is an easy way to edit or delete your range
names. Simply open the Name Manager by selecting the Formulas tab and then clicking
Name Manager. You will now see a list of all range names. For example, for the file States.
xlsx, the Name Manager dialog box will look like Figure 2-10.

FIGURE 2-10 Name Manager d a og box for States.x sx.


14 Microsoft Excel 2010: Data Analysis and Business Modeling

To edit any range name, simply double-click the range name or select the range name and
click Edit. Then you can 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, first select the range names you want to delete. If the
range names are listed consecutively, simply select the first 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 let’s look at some specific examples of how to use range names.

Answers to This Chapter’s Questions


I want to total sales in Arizona, California, Montana, New York, and New Jersey . Can I
use a formula to compute total sales in a form such as AZ+CA+MT+NY+NJ instead of
SUM(A21:A25) and still get the right answer?

Let’s return to the file States.xlsx, in which we 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, you could clearly use the formula SUM(B6:B9). You could also point to cells B6, B7,
B8, and B9, and the formula would be entered as AL+AK+AZ+AR. The latter formula is, of
course, much easier to understand.

As another illustration of how to use range names, look at the file Historicalinvest.xlsx, shown
in Figure 2-11, which contains annual percentage returns on stocks, T-Bills, and bonds. (Some
rows are hidden in this figure; the data ends in row 89.)

FIGURE 2-11 H stor ca nvestment data.


Chapter 2 Range Names 15

After selecting the cell range B7:D89 and choosing Formulas, Create From Selection, I created
names in the top row of the range. The range B8:B89 is named Stocks, the range C8:C89
T.Bills, and the range D8:D89 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 appears, as shown in Figure 2-12.

FIGURE 2-12 You can add a range name to a formu a by us ng the Paste Name d a og box.

Then 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 (12.05
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!

I would be remiss if I did not mention the exciting AutoComplete capabilities of Excel 2010. If
you begin typing Average(T, Excel shows you a list of range names and functions that begin
with T. Then you can simply double-click T.Bills to complete the entry of the range name.

What does a formula like Average(A:A) do?

If you use a column name (in the form A:A, C:C, and so on) in a formula, Excel treats an entire
column as a named range. For example, entering the formula AVERAGE(A:A) will average
all numbers in column A. Using a range name for an entire column is very helpful if you
frequently enter new data into a column. For example, if column A contains monthly sales
of a product, as new sales data is entered each month, our formula computes an up-to-date
monthly sales average. I caution you, however, that if you enter the formula AVERAGE(A:A)
in column A, you will get a circular reference message because the value of the cell contain-
ing the average formula depends on the cell containing the average. You will learn how to
resolve circular references in Chapter 11, “Circular References.” Similarly, entering the formula
AVERAGE(1:1) will average all numbers in row 1.

What is the difference between a name with workbook scope and one with worksheet
scope?

The file Sheetnames.xlsx will help you understand the difference between range names that
have workbook scope and range names that have worksheet scope. When you create names
16 Microsoft Excel 2010: Data Analysis and Business Modeling

with the Name box, the names have 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. Then if you enter a formula such as SUM(sales) in
any worksheet, you obtain an answer of 7. This is because the Name box creates names with
workbook scope, so anywhere in the workbook where 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 formula SUM(sales), 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. Next you go to the Name Manager, give the name jam to cells E4:E6 of Sheet1,
and define the scope of this name as Sheet1. Then you move to Sheet2, go to the Name
Manager, and give the name jam to cells E4:E6, and define the scope of this name as Sheet2.
The Name Manager dialog box now looks like Figure 2-13.

FIGURE 2-13 Name Manager d a og box w th worksheet and workbook names.

Now, what if you enter the formula SUM(jam) 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
formula SUM(jam) will yield a #NAME? error because there is no range named jam defined
in Sheet3. If you enter anywhere in Sheet3 the formula SUM(Sheet2!jam), Excel will recog-
nize the worksheet-level name that represents cell range E4:E6 of Sheet2 and yield a result
of 3 + 4 + 5 12. Thus, prefacing a worksheet-level name by its sheet name followed by an
exclamation point (!) allows you to refer to a worksheet-level range in a worksheet other than
the sheet in which the range is defined.
Chapter 2 Range Names 17

I really am getting to like range names . I have started defining range names for many of
the workbooks I have developed at the office . However, the range names do not show up
in my formulas . How can I make recently created range names show up in previously cre-
ated formulas?

Let’s look at the file Applynames.xlsx. See Figure 2-14.

FIGURE 2-14 How to app y range names to formu as.

I entered the price of a product in cell F3, and product demand of 10000–300*F3 in cell F4.
The unit cost and fixed cost are entered in cells F5 and F6, respectively, and profit is comput-
ed in cell F7 with the formula F4*(F3–F5)–F6. I used Formulas, Create From Selection, and
chose the Left Row option to name cell F3 price, cell F4 demand, cell F5 unit cost, cell F6 fixed
cost, and cell F7 profit. You would like these range names to show up in the cell F4 and cell F7
formulas. To apply the range names, first select the range where you want the range names
applied (in this case, F4:F7). Now go to the Defined Names group on the Formulas tab, click
the Define Name arrow, and then click Apply Names. Highlight the names you want to apply,
and then click OK. Note that cell F4 now contains the formula 10000–300*price and cell F7
contains the formula demand*(price–unitcost)–fixed cost, as you wanted.

By the way, if you want the range names to apply to the entire worksheet, simply select the
entire worksheet 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 display the Paste Name box, and then click the Paste List button. (See
Figure 2-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 file Last year.xlsx contains the solution to this problem. As shown in Figure 2-15, we want
to compute revenues for 2012–2018 that grow at 10 percent per year off a base level of $300
million in 2011.
18 Microsoft Excel 2010: Data Analysis and Business Modeling

FIGURE 2-15 Creat ng a range name for last year.

To begin, we use the Name box to name cell B3 growth. Now comes the neat part! Move
the cursor to B7 and bring up the New Name dialog box by clicking Define Name in the
Defined Names group on the Formulas tab. Then fill in the New Name dialog box as shown
in Figure 2-16.

FIGURE 2-16 n any ce , th s name refers to the ce above the act ve ce .

Because we are in cell B7, Excel interprets this range name to always refer to the cell above
the current cell. Of course, this would not work if the cell reference B6 contains any dollar
signs. Now if we enter in cell B7 the formula lastyear*(1+growth) and copy it down to the
range B8:B13, each cell will contain the formula we 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 formula wages*hours?

As shown in Figure 2-17 (see the file Namedrows.xlsx), row 12 contains daily wage rates, and
row 13 contains hours worked each day.
Chapter 2 Range Names 19

FIGURE 2-17 n any ce , th s name refers to the ce above the act ve ce .

You can simply select row 12 (by clicking on the 12) and use the Name box to enter the name
wage. Then select row 13 and use the Name box to enter the name hours. If you now enter
in cell F14 the formula wage*hours and copy this formula to the range G14:L14, you can see
that in each column Excel finds the wage and hour values and multiplies them.

Remarks
■ Excel does not allow you to use the letters r and c as range names.
■ If you use Create From Selection to create a range name and your name contains
spaces, Excel inserts an underscore ( ) to fill in the spaces. For example, the name
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 2010 has over 16,000 columns,
a range name such as cat1 is not permitted because there is a cell CAT1. If you try and
name a cell CAT1, Excel tells you the name is invalid. Probably your best alternative is to
name the cell cat1 .
■ The only symbols allowed in range names are periods (.) and underscores ( ).

Problems
1. The file Stock.xlsx 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 worksheet and name the range containing the cells A1:B3 and A6:B8 as Red.
3. Given the latitude and longitude of any two cities, the file Citydistances.xlsx computes
the distance between the two cities. Define 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 file Sharedata.xlsx 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 formula
shares*price.
5. Create a range name that averages the last five years of sales data. Assume annual sales
are listed in a single column.

You might also like