Adding a New Series

To add a new series to a chart, we use the Add method of the SeriesCollection object. The syntax is:

SeriesCollectionObject.Add(Source, Rowcol, SeriesLabels, CategoryLabels, Replace)

The Source parameter specifies the new data as a Range object.

The optional Rowcol parameter specifies whether the data series are in rows or columns in the specified range. It can be one of the following XlRowCol constants:

Enum XlRowCol xlRows = 1

xlColumns = 2 ' The default

End Enum

The optional SeriesLabels parameter applies only when Source is a range (not an array). It is True if the first row or column contains the name of the data series and False if the first row or column contains the first data point of the series. If this argument is omitted, Excel attempts to determine the location of the series name from the contents of the first row or column. (As I have stated several times before, my advice is to supply any values that you require, rather than letting Excel guess.)

Similarly, the optional CategoryLabels parameter applies only when Source is a range (not an array). It is True if the first row or column contains the name of the category labels and False if the first row or column contains the first data point of the series. If this argument is omitted, Excel attempts to determine the location of the category label from the contents of the first row or column.

The optional Replace parameter has the following meaning: if CategoryLabels is True and Replace is True, the specified categories replace the categories that currently exist for the series. If Replace is False, the existing categories will not be replaced. The default value is False.

To illustrate, consider the worksheet in Figure 21-25.

0 0

Post a comment