Add A New Data Series To A Chart

After you create a chart, you can redefine the range of data Excel uses to display values on the chart by adding a new data series. A data series consists of a group of data values, which Excel displays on the chart. For example, if you have a bar chart showing the monthly sales in Dallas for each month the year, you can add another data series which contained the sales in Miami for the year.

To define a new data series to add to the existing range of data, you create a new Series object and add it to the SeriesCollection collection object with the Add method. The SeriesCollection collection object represents all data series Excel plots on a specific chart, with each data series representing a new Series object.

To add a new data series to the chart, you use the Add method. When you use the Add method with a

SeriesCollection object, you can use five different parameters: Source, Rowcol, SeriesLabels, CategoryLabels, and Replace. You must specify a Source parameter to indicate the data series to add to the chart. Remember, you only need to specify the range for the new data series;if the range you specify includes the existing range, Excel duplicates those values on the chart.

Use the Rowcol parameter to indicate whether the new values are in rows or columns by specifying a constant of xlColumns or xlRows. Setting the SeriesLabels and CategoryLabels parameters indicates that the first row or column contains the corresponding labels. If you specify a value of True for the CategoryLabels parameter and the Replace parameter, Excel replaces the current category labels with the labels from the new range.

ADD A NEW DATA SERIES TO A CHART

ADD A NEW DATA SERIES TO A CHART

Vba Multiplication Table Programming

L-D Create a new subroutine. ype Dim UseChart As

Chart, replacing UseChart with the Chart variable.

LH Type Set UseChart = ThisWorkbook.Charts(1), replacing

ThisWorkbook.Charts (l) with the chart reference.

L-D Create a new subroutine. ype Dim UseChart As

Chart, replacing UseChart with the Chart variable.

LH Type Set UseChart = ThisWorkbook.Charts(1), replacing

ThisWorkbook.Charts (l) with the chart reference.

WORKING WITH CHARTS

Exin

After you specify the range of data for a chart, you can extend the values used of particular data series. When you extend a data series, you add additional data values to the end of a particular data series. You can extend an existing data series collection using the Extend method with the SeriesCollection object. The Extend method provides three different parameters for extending the data series. The Source parameter indicates the source of the data values to add to the existing data series. You can use the Rowcol parameter to stipulate whether the new values are in rows or columns. You specify the value for this parameter with either the xlRow or xlColumn parameter. If the new range contains category labels in the first row, specify True for the CategoryLabels parameter. The following code illustrates how to extend a data series:

You can remove a series for a chart using the Delete method. To remove a data series from a chart, you need to use the index value of the series you want to remove, as illustrated in the following code, which removes the second data series:

Example:

SelectChart2.SeriesCollection(2).Delete

Example:

SelectChart2.SeriesCollection.Extend Source:=Worksheets("Sheet1").Range("A10:D13")

Name Legend Example

—Q Type UseChart.SeriesCollection. Add Source:=Worksheets ("Sheet1").Range("D1:D7"), replacing Worksheets ("Sheet1").Range ("D1:D7") with the range to add to the chart.

0 Switch to Excel and run L-■ Excel adds the specified the macro. data series to the chart.

—Q Type UseChart.SeriesCollection. Add Source:=Worksheets ("Sheet1").Range("D1:D7"), replacing Worksheets ("Sheet1").Range ("D1:D7") with the range to add to the chart.

0 Switch to Excel and run L-■ Excel adds the specified the macro. data series to the chart.

Was this article helpful?

+1 -1

Responses

Post a comment