Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Easily Changing Chart Data Ranges.

Easily Changing Chart Data Ranges

by Allen Wyatt
(last updated September 27, 2016)

3

Excel is great when it comes to creating charts based on data in a data table. The Chart Wizard can quickly identify an entire data table, or you can select a portion of a data table and use the Chart Wizard to create a chart based just on that portion.

If you change the data range for your chart quite often, it can get tiresome to continually pull up the Chart Wizard and change the data range reference. For instance, if you have a data table that includes several years worth of data, you may want to view a chart that is based on the first five years of data, and then change the data range so the chart refers to a different subset of the data. Make the changes often enough in the Chart Wizard, and you'll start casting about for ways to make the changes easier (and more reliably) than with the wizard.

One way to do this is with the use of named ranges and several worksheet functions. Let's say that your chart is embedded on a worksheet, but the worksheet is different than the one where the source data is located. On the same sheet as the chart, create two input cells which will serve as "from" and "to" indicators. Name these two cells something like FromYear and ToYear.

On your data worksheet (the one without the chart; I'll call it "Source Data"), the data is arranged with each year in a separate column and a series of cost factors in each row. Start your table in column F and place your years in row 2. Place the cost factors in column E, starting at row 3. Above the years place a capital letter that is the same as the column letter, and in column D place a number that is the same as the row number of the data. (See Figure 1.)

Figure 1. First phase of data preparation.

In this example, the chart that is embedded on the other worksheet is based on the data in the rangeF2:I5. There is nothing special about the chart, but the changes you are getting ready to make will make it dynamic, and therefore much more useful.

Start by placing the following formula in cell B1:

="Trends For " & IF(FromYear=ToYear,FromYear,FromYear & " to " & ToYear)

This formula provides a dynamic title that you will later use for your chart. Give cell B1 the name addrTitle, then place the following formula in cell B2:

="'Source Data'!$" & INDEX($F$1:$I$1,1,MATCH(FromYear,$F$2:$I$2)) & "$" & D2 & ":$" & INDEX($F$1:$I$1,1,MATCH(ToYear,$F$2:$I$2)) & "$" & D2

Copy the formula in B2 to the cells B3:B5. The formula returns address strings that represent the desired ranges for the X-axis values and the data series. The actual ranges returned by the formulas will vary, based on the values you enter in the FromYear and ToYear cells on the other worksheet. To make things clearer you can enter some labels into column A. (See Figure 2.)

Figure 2. Second phase of data preparation.

Now you need to name each of the cells in the range B2:B5. Select B2 and in the Name Box (just above column A) enter the name "addrXVal" (without the quotes). Similarly name B3 as addrCost1, B4 as addrCost2, and B5 as addrCost3.

The next step is to create a couple of named formulas that you can use in creating the charts. Choose Insert | Name | Define to display the Define Name dialog box. (See Figure 3.)

Figure 3. The Define Name dialog box.

In the name area, at the top of the dialog box, type "rngXVal" (without the quotes), then type the following in the Refers To box:

=INDIRECT(addrXVal)

Using the same dialog box, define additional names (rngCost1, rngCost2, and rngCost3) that use the same type of INDIRECT formula to refer to the ranges addrCost1, addrCost2, and addrCost3, respectively.

Now you are finally ready to update the references in your chart. Right-click the chart and select Source Data, then make sure the Series tab is displayed. (See Figure 4.)

Figure 4. The Series tab of the Source Data dialog box.

For each of the data series listed at the left side of the dialog box, enter the Name and Values according to the names you defined. Thus, for the Cost1 series you would enter a Name of ='Source Data'!addrCost1 and a Values of ='Source Data'!rngCost1. You would use the similar references and names for each of the other data series, as well.

Note that you must include the name of your worksheet (Source Data), within apostrophes, in the references you enter. In the Category (X) Axis Labels reference you can enter ='Source Data'!rngXVal.

Once this is done, you can change the starting and ending years in the FromYear and ToYear cells, and Excel automatically and immediately updates the chart to represent the data you specified.

For an extra touch, if you haven't already added a chart title, go ahead and do so. Right-click the chart and select Chart Options, then display the Titles tab. (See Figure 5.)

Figure 5. The Titles tab of the Chart Options dialog box.

Enter anything you'd like in the Chart Title box (you'll replace it in a moment), then click OK. The chart title should already be selected, but if it isn't, click on it once. You should see the selection box around the title. In the Formula bar enter the following:

='Source Data'!addrTitle

The chart title is now linked back to the cell containing the title string, which in turn is dynamically updated each time you change the FromYear and ToYear values.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2376) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Easily Changing Chart Data Ranges.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Automatic Question Numbering

Want to use Word's numbering capabilities to help you number a series of questions? Here's how to accomplish the task as ...

Discover More

Shortcut for Viewing Formulas

If you need to switch between viewing formulas and viewing the results of those formulas, you'll love the keyboard shortcut ...

Discover More

Quickly Formatting Footers in Documents with Many Sections

Need to adjust all the footers or headers in a document that uses lots of them? It's easy to do if you understand how the ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (menu)

Moving Groups of Data Labels at One Time

Having problems working with data labels in your charts? That's not unusual; here's an idea of an add-in that could help you ...

Discover More

Multiple Data Points in a Chart Column

Excel provides lots of ways you can create charts. This tip provides some pointers on how you can combine stacked column ...

Discover More

Controlling the Plotting of Empty Cells

When creating a chart from information that contains empty cells, you can direct Excel how it should proceed. This tip ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 4?

2017-03-29 19:52:35

Scott

How can I make an Excel chart refer to the first three letters in a row.

Reason: I'm trying to chart certain cells in the same row that start with "NHS". However I cant filter the data sheet because it is shared between departments.


Regards
Scott.


2015-03-11 14:56:46

pavan

Hi,

I have 3 data set like a b & c. while representing charting, i would like to show a&b together & c as a separate set.
Could you please help me on this.

Thanks & Regards,
Pavan


2013-10-21 09:10:50

Jim Autrey

I may have done somthing incorrectly, but it seems the formula for NAME may be wrong. The tip states "enter a Name of ='Source Data'!addrCost1". This causes the name to be "'Source Data'!$F$3:$i$3". I defined a name for cells A3 through A5 as nameCost1, nameCost2, and nameCost3. I used that as the formulat for NAME and got the names I was expecting. Other than that, everything worked great. Great tip.


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.