Microsoft KB Archive/104185

{|
 * width="100%"|

XL: Using Defined Names to Automatically Update Chart Range

 * }

-

The information in this article applies to:


 * Microsoft Excel for Windows, versions 2.x, 3.0, 4.0, 4.0a
 * Microsoft Excel for OS/2, version 2.2, 3.0
 * Microsoft Excel for the Macintosh, versions 2.x, 3.0, 4.0

-

To set up a chart that is automatically updated as you add new information to an existing chart range, use either of the following methods.

Method 1: Use OFFSET with a defined name
To use this method, follow these steps:

  In a new worksheet, type the following data:

      A1:  Month    B1:  Sales A2: Jan      B2:  10 A3: Feb      B3:  20 A4: Mar      B4:  30  Choose Define Name from the Formula menu. In the Name box, type "Date" (without the quotation marks). In the Refers To box, type:

=OFFSET($A$2,0,0,COUNTA($A$2:$A$200),1) Choose Add. In the Name box, type "Sales" (without the quotation marks). In the Refers To box, type:

=OFFSET($B$2,0,0,COUNT($B$2:$B$200),1) Clear cell B2, and type the following formula:

=RAND*0+10

NOTE: The above formula, using the volatile function "RAND", is needed to automatically update the OFFSET formula used in the defined name "Sales" when new data is entered into column B. The value "10", used in this formula is the original value of cell B2.</li> To create a new chart, select the data, choose New from the File menu and select the Chart option.</li> From the Chart menu, choose Edit Series.</li> Choose "Sales" as the series to edit.</li> In the formula in the X Labels box, replace the cell reference with the defined name Date. For example, the formula might read, =FILENAME.XLS!Date.</li> In the formula in the Y Values box, replace the cell reference with the defined name Company. For example, the formula might read, =FILENAME.XLS!Sales.</li></ol>

Method 2: Use a database, OFFSET, and defined names
You can also define your data as a database and create defined names for each chart data series. To do this, follow these steps:

<ol>  In a new worksheet, type the following data:

<pre class="FIXEDTEXT">      A1:  Month    B1:  Sales A2: Jan      B2:  10 A3: Feb      B3:  20 A4: Mar      B4:  30 </li> Select the range from A1 to B4 and choose Set Database from the Data menu.</li> From the Formula menu, choose Define Name.</li> In the Name box, type "Date" (without the quotation marks).</li> In the Refers To box, type:

=OFFSET(Database,1,0,ROWS(Database)-1,1)</li> Choose Add.</li> In the Name box, type "Sales" (without the quotation marks).</li> In the Refers To box, type:

=OFFSET(Database,1,1,ROWS(Database)-1,1)</li> Select the range A1:B4, and create a chart by choosing New from the File menu, and then selecting Chart from the list.</li> From the Chart menu, choose Edit Series.</li> <li>Choose "Sales" as the series to edit.</li> <li>In the formula in the X Labels box, replace the cell reference with the defined name Date. For example, this formula might read, =FILENAME.XLS!Date.</li> <li>In the formula in the Y Values box, replace the Cell Reference with the defined name Company. For example, this formula might read, =FILENAME.XLS!Sales.</li></ol>

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

NOTE: If you are creating a series chart that plots every value in a contiguous block of cells in single column starting from row 1, you can use either of the following formulas in the refers to portion of the defined name:

<pre class="FIXEDTEXT">  =INDIRECT("Sheet1!$a$1:$a"&COUNT(Sheet1!$A:$A))

-or-

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

To start on a row other than one, 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 contiguous non-numeric entries (such as labels), use COUNTA instead of COUNT.