XL: Using Defined Names to Automatically Update Chart Range

ID: Q104185


The information in this article applies to:

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:

  1. In a new worksheet, type the following data:

    
           A1:  Month    B1:  Sales
           A2:  Jan      B2:  10
           A3:  Feb      B3:  20
           A4:  Mar      B4:  30 


  2. Choose Define Name from the Formula menu.


  3. In the Name box, type "Date" (without the quotation marks).


  4. In the Refers To box, type:

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


  5. Choose Add.


  6. In the Name box, type "Sales" (without the quotation marks).


  7. In the Refers To box, type:

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


  8. 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.


  9. To create a new chart, select the data, choose New from the File menu and select the Chart option.


  10. From the Chart menu, choose Edit Series.


  11. Choose "Sales" as the series to edit.


  12. 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.


  13. 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.


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:

  1. In a new worksheet, type the following data:

    
           A1:  Month    B1:  Sales
           A2:  Jan      B2:  10
           A3:  Feb      B3:  20
           A4:  Mar      B4:  30 


  2. Select the range from A1 to B4 and choose Set Database from the Data menu.


  3. From the Formula menu, choose Define Name.


  4. In the Name box, type "Date" (without the quotation marks).


  5. In the Refers To box, type:

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


  6. Choose Add.


  7. In the Name box, type "Sales" (without the quotation marks).


  8. In the Refers To box, type:

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


  9. Select the range A1:B4, and create a chart by choosing New from the File menu, and then selecting Chart from the list.


  10. From the Chart menu, choose Edit Series.


  11. Choose "Sales" as the series to edit.


  12. 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.


  13. 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.


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:


   =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().

REFERENCES

"User's Guide 1," version 4.0, pages 306-325, 434-451
"Function Reference Guide," version 4.0, pages 68, 69, 299

Additional query words: 2.00 2.0x 4.00a database counta count dynamic


Keywords          : 
Version           : WINDOWS: 2.0,3.0,4.0,4.0a; MACINTOSH: 2.0,3.0,4.0
Platform          : MACINTOSH OS/2 WINDOWS 
Issue type        : kbhowto 

Last Reviewed: April 6, 1999