Microsoft KB Archive/183446

= How to use defined names to automatically update a chart range in Excel =

Article ID: 183446

Article Last Modified on 5/18/2007

-

APPLIES TO


 * Microsoft Office Excel 2007
 * Microsoft Office Excel 2003
 * Microsoft Excel 2002 Standard Edition
 * Microsoft Excel 2000 Standard Edition
 * Microsoft Excel 97 Standard Edition
 * Microsoft Excel 95 Standard Edition
 * Microsoft Excel 5.0 Standard Edition

-



This article was previously published under Q183446



SUMMARY
To set up a chart that is automatically updated as you add new information to an existing chart range in Microsoft Excel, create defined names that dynamically change as you add or remove data.



MORE INFORMATION
This section includes two methods for using defined names to automatically update the chart range.

Note The methods in this section assume there are no more than 200 rows of data. You can revise the defined names so that they use the appropriate number and reflect the maximum number of rows.

Method 1: Use OFFSET with a defined name
To use this method, follow these steps, as appropriate for the version of Excel that you are running.

Microsoft Office Excel 2007
  In a new worksheet, type the following data:        A1:  Month    B1:  Sales A2: Jan      B2:  10 A3: Feb      B3:  20 A4: Mar      B4:  30  On the Formulas tab, click Define Name in the Defined Names group. In the Name box, type Date . In the Refers to box, type =OFFSET($A$2,0,0,COUNTA($A$2:$A$200),1), and then click OK. On the Formulas tab, click Define Name in the Defined Names group. In the Name box, type Sales .</li> In the Refers to box, type =OFFSET($B$2,0,0,COUNTA($B$2:$B$200),1), and then click OK.</li> Clear cell B2, and then type the following formula:

=RAND*0+10

Note This formula uses the volatile RAND function. The formula automatically updates the OFFSET formula that is used in the defined name "Sales" when you enter new data into column B. The value 10, which is used in this formula, is the original value of cell B2.</li> Select cells A1:B4.</li> On the Insert tab, click a chart, and then click a chart type.</li> Click the Design tab, click the Select Data in the Data group.</li> Under Legend Entries (Series), click Edit.</li> In the Series values box, type =Sheet1!Sales, and then click OK.</li> Under Horizontal (Category) Axis Labels, click Edit.</li> In the Axis label range box, type =Sheet1!Date, and then click OK.</li></ol>

Microsoft Office Excel 2003 and earlier versions of Excel
<ol>  In a new worksheet, type the following data: <pre class="fixed_text">       A1:  Month    B1:  Sales A2: Jan      B2:  10 A3: Feb      B3:  20 A4: Mar      B4:  30 </li> On the Insert menu, point to Name, and then click Define.</li> In the Names in workbook box, type Date .</li> In the Refers to box, type:

=OFFSET($A$2,0,0,COUNTA($A$2:$A$200),1)

</li> Click Add.</li> In the Names in workbook box, type Sales .</li> In the Refers to box, type the following text:

=OFFSET($B$2,0,0,COUNT($B$2:$B$200),1)

</li> <li>Click Add, and then click OK.</li> <li>Clear cell B2, and then type the following formula:

=RAND*0+10

Note This formula uses the volatile RAND function. The formula automatically updates the OFFSET formula that is used in the defined name "Sales" when you enter new data into column B. The value 10, which is used in this formula, is the original value of cell B2.</li> <li>Select $A$1:$B$4.</li> <li> Create the chart, and then add the defined names in the chart. To do this, follow these steps, as appropriate for the version of Excel that you are running.

Microsoft Excel 97 through Excel 2003
<ol style="list-style-type: lower-alpha;"> <li>On the Insert menu, click Chart to start the Chart Wizard.</li> <li>Click a chart type, and then click Next.</li> <li>Click the Series tab. In the Series list, click Sales.</li> <li>In the Category (X) axis labels box, replace the cell reference with the defined name Date.

For example, the formula might be similar to the following:

=Sheet1!Date

</li> <li>In the Values box, replace the cell reference with the defined name Sales.

For example, the formula might be similar to the following:

=Sheet1!Sales

</li> <li>Click Next.</li> <li>Make any changes you want in step 3 of the Chart Wizard and click Next.</li> <li>Specify the chart location and click Finish.</li></ol>

Microsoft Excel 5.0 or Microsoft Excel 7.0
<ol style="list-style-type: lower-alpha;"> <li>On the Insert menu, point to Chart, and click As New Sheet to start the Chart Wizard.</li> <li>Click Next.</li> <li>Click a chart type, and then click Next.</li> <li>Click a chart subtype, and then click Next.</li> <li>Click Columns for Data Series In and type 1 for Use First 1 Columns for Category (x) Axis Labels. Click Next.</li> <li>Click the titles that you want to display and click Finish.

The chart appears on a new chart.</li> <li>Select the data series. On the Format menu, click Select Data Series.</li> <li>Click the X Values tab. In the X Values box, replace the cell reference with the defined name Date.

For example, the formula might be similar to the following:

=Sheet1!Date

</li> <li>Click the Name And Values tab. In the Y Values box, replace the cell reference with the defined name Sales.

For example, the formula might be similar to the following:

=Sheet1!Sales

</li> <li>Click OK.</li></ol> </li></ol>

Method 2: Use a database, OFFSET, and defined names in Excel 2003 and in earlier versions of Excel
You can also define your data as a database and create defined names for each chart data series. To use this method, follow these steps: <ol> <li> In a new worksheet, type the following data: <pre class="fixed_text">      A1:  Month    B1:  Sales A2: Jan      B2:  10 A3: Feb      B3:  20 A4: Mar      B4:  30 </li> <li>Select the range A1:B4, and then click Set Database on the Data menu.</li> <li>On the Formula menu, click Define Name.</li> <li>In the Name box, type Date .</li> <li>In the Refers to box, type:

=OFFSET(Database,1,0,ROWS(Database)-1,1)

</li> <li>Click Add.</li> <li>In the Name box, type Sales .</li> <li>In the Refers to box, type:

=OFFSET(Database,1,1,ROWS(Database)-1,1)

</li> <li>Click Add, and then click OK.</li> <li>Select $A$1:$B$4</li> <li>Repeat step 10 from method 1 to create the chart and add the defined names to the chart.</li></ol>

As long as the data that you want to appear in your chart is defined as a database, the chart is updated automatically as you add new data.

Note If you are creating a series chart that plots every value in an adjacent block of cells in single column, and the block of cells starts with the first row, you can use either of the following formulas in the Refers to box for the defined name:

=INDIRECT("Sheet1!$a$1:$a"&COUNT(Sheet1!$A:$A))

=Sheet1!$A$1:OFFSET(Sheet1!$A$1,COUNT(Sheet1!$A:$A),0)

To use a block of cells that start with a cell on a row other than the first row, reference that row in the first cell reference and add the starting row number to the count to find the last row number. To plot adjacent nonnumeric entries (for example, labels), use COUNTA instead of COUNT.

Additional query words: XL2003 XL2002 XL2000 XL97 database counta count dynamic XL2007

Keywords: kbchart kbhowto KB183446

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.