Creating automatically extended plot ranges
To force Excel to update your chart automatically when you add new data, follow these steps:
1. On the Formulas tab, in the Defined Names group, click Define Name:
2. In the New Name dialog box:
- In the Name field, enter Data,
- In the Refers to field, enter this formula:
= OFFSET (<Sheet name>!<start cell>, 0, 0, COUNTA (<Sheet name>!<Column name>: <Column name>) - 1)
The OFFSET function returns a cell or range of cells that is a specified number of rows and columns from a cell or range of cells:
= OFFSET (<reference>, <row>, <column>, [height], [width])
Note: How to use the range from row instead of column, see below in the tip.
- Click OK.
Notice that the OFFSET function refers to the first data point (cell B5) and uses the COUNTA function to get the number of data points in the column.
3. Define a new data range, in the New Name dialog box:
- In the Name field, type Sales,
- In the Refers to field, enter the appropriate formula for Sales data:
- Click OK to close the dialog box.
4. Create the chart.
5. Change the range of data series and axis with the names that you defined in Steps 2 and 3:
- Series values: <Excel-file name>!Sales
- Axis label range: <Excel-file name>!Data
After you perform these steps, when you add data to columns B and C, the chart updates automatically to show the new data (see on the top of this screen). To use this technique for your own data, make sure that the first argument for the OFFSET function refers to the first data point, and that the argument for COUNTA refers to the entire column of data. Also, if the columns used for the data contain any other entries, COUNTA will return an incorrect value.
- At the moment, the secondary axes don't change dynamically, depending on the data.
- In this example, the COUNTA formula was used to avoid counting blank cells.
Cells with formulas or filled with irrelevant information such as comments will also be counted as non-empty.
In this case, it is necessary to replace the COUNTA formula by another one. For example:
- COUNT will count only cells with numbers, but it also has issues depending on the formula. In some cases, the COUNT formula can calculate some formula results that you don't want to show in the chart.
- COUNTIF will count cells that contain numbers. For example:
COUNTIF (<data range>, ">0").
- If you need to use the data from rows instead of columns, change the formula code to:
= OFFSET (<Sheet name>!<start cell>, 0, 0, 1, COUNTA (<Sheet name>!<Row name>: <Row name>) - 1):
See also this tip in French: Comment créer les graphiques avec les plages de tracé étendues automatiquement.