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

Easily Changing Chart Data Ranges

by Allen Wyatt
(last updated June 2, 2014)

4

Excel is great when it comes to creating charts based on data in a data table. You can use the tools on the Insert tab of the ribbon to quickly identify an entire data table or you can select a portion of a data table and use the same tools 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 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 and you'll start casting about for ways to make the changes easier (and more reliably).

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 name the worksheet "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 range F2: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.

Still working on the "Source Data" worksheet, 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

Remember that this is a single formula, although it is shown on two lines here for clarity. 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. Display the Formulas tab of the ribbon and click the Define Name tool to display the New Name dialog box. (See Figure 3.)

Figure 3. The New 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)

Click OK and the name is defined. Then, using the same New Name 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 choose Select Source or Select Data, depending on your version of Excel. Excel displays the Select Data Source dialog box. (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, click the Edit button and 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. If you are using Excel 2007 or Excel 2010, select the chart, display the Layout tab of the ribbon, click the Chart Title tool, and choose the way you want the title to appear. The title should appear immediately in the chart.

If you are using Excel 2013, click the Chart Elements icon, near the upper-right corner of your chart. (It looks like a plus sign.) Excel displays a "fly-out" menu that lists various elements you can add to your chart. (See Figure 5.)

Figure 5. Adding titles to a chart in Excel 2013.

Make sure you a check mark appears beside the Chart Title element. The title should appear immediately in the chart.

Regardless of the version of Excel you are using, click the title (within the chart itself) once to select it. 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 (8667) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel 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

Sorting by Fill Color

Sorting data in a worksheet is easy, unless you want to sort by the color used to fill a range of cells. There are ways to do ...

Discover More

Removing Entire Paragraphs from Your Document

If you need to get rid of a lot of paragraphs in a document, it's easy to do as long as the document relies on styles for ...

Discover More

Stopping Word from Changing Characters in an E-mail Address

When you type an e-mail address, Word generally recognizes it as such. What do you do, though, if Word changes the e-mail ...

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 (ribbon)

Plotting Times of Day

Got a chart created from your worksheet? You can plot times of day in the chart if you apply the simple techniques in this ...

Discover More

Adjusting Your View of 3-D Graphs

Do you use Excel's charting capabilities to display three-dimensional views of your data? The program provides a way that you ...

Discover More

Changing the Axis Scale

When creating a chart, you may want to adjust the default scaling that Excel applies to an axis. This is relatively easy to ...

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 3 + 8?

2016-12-08 15:45:32

BJ Gray

Never mind. I finally realized that the letter row and number columns you put in are to fool Excel into thinking that the index function is returning a cell address. Got it sorted.


2016-12-08 13:36:32

BJ Gray

I am really interested in implementing this method, but have been banging my head for the past day and a half.

I can't get the named formulas to work on the graph at all. I have checked and rechecked how I named the cells and established the named formulas with the indirect function.

Oddly, I can get the chart title to appear.

Any suggestions?

Thank you.


2014-11-11 19:58:47

David Rabbit

What I want is a chart that works like a simple moving average works, and charts the latest N data points. As a new data point is added the first one drops off, so I always have the last (eg.) 100 data points automatically


2013-12-13 11:31:33

DEB

I SEE WHERE TO PULL UP THE DATASOURCE
TO CHANGE CHART DATA,

FROM THERE IT APPEARS TO BE A JOKE,
I HAVE TRIED REPEATEDLY TO JUST GET THE CURSOR TO THE RIGHT POSITION WITH THE RIGHT ARROW KEY, IT ONLY PUTS IN NEW FIELDS, NOT AT ALL WHAT I WANT.

THIS WAS SO SIMPLE BEFORE, I HAVE WASTED 1/2 HOUR TRYING TO FIGURE THIS OUT. GEESH


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu 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.