Adding noncontiguous ranges as series in xyscatter chart

  • Thread starter Thread starter Kristina Engdahl
  • Start date Start date
K

Kristina Engdahl

Hi,
I'm trying to add data to a serie using Visual Basic for applications.
The data exist in noncontiguous ranges for both x-values and y-values.
I would like to add several series in this way and have tried the
following:

Dim newSerie As Series
Set newSerie = newChart.SeriesCollection.NewSeries
newSerie.Values = Union(yColumn, yCell)
newSerie.xValues = Union(xColumn, xCell)

I think the problem is that the ranges are noncontiguous but don't
understanf why it doesn't work. It is no problem to add data like this
by hand using the addSeries-function in the Chart-wizarard.

I have also tries the Extend function for the seriesCollection by
first sdding one range and then trying to extend with the other but
don't get how I can specify which serie the new data should be added
to.

I would much appreciate if someone could give me a hint on how to
solve this problem.

Regards,
Kristina
 
Start with a contiguous area, then add on with .SeriesCollection.Extend
Try recording a macro while you do it manually.

Jerry
 
Hi,
I still haven't been able to record a macro where I can see how I
define which serie that should get the new point. I used the addData
in the chart menu. When I do this all my data get in the first serie.
For example if I have three series and would like to add a single
datapoint to each serie all new data is added to the first serie.

Here is an example of code that does not work, I tried to order the
new data in xy-pairs before adding them to the seriescollection.
The "orignalData" holds ranges of about ten rows and the "newData" is
an array that have only single rows of data.

for i = 1 to 3
Dim newSerie As Series
Set newSerie = newChart.SeriesCollection.NewSeries
newSerie.xValues = orignalData(i).Columns(xColumn)
newSerie.Values = orignalData(i).Columns(yColumn)
next i

Dim rng As Range
Set rng = Union(newData(1).Columns(2), newData(1).Columns(3),
newData(2).Columns(2), newData(2).Columns(3), newData(3).Columns(2),
newData(3).Columns(3))

newChart.SeriesCollection.Extend Source:=rng, Rowcol:=xlRows,
CategoryLabels:=True

The only solution I can see now is to rearrange my data in to a new
table and this is not something that I would like to do.

Regards,
Kristina
 
Hi,
I still haven't been able to record a macro where I can see how I
define which serie that should get the new point. I used the addData
in the chart menu. When I do this all my data get in the first serie.
For example if I have three series and would like to add a single
datapoint to each serie all new data is added to the first serie.

Here is an example of code that does not work, I tried to order the
new data in xy-pairs before adding them to the seriescollection.
The "orignalData" holds ranges of about ten rows and the "newData" is
an array that have only single rows of data.

for i = 1 to 3
Dim newSerie As Series
Set newSerie = newChart.SeriesCollection.NewSeries
newSerie.xValues = orignalData(i).Columns(xColumn)
newSerie.Values = orignalData(i).Columns(yColumn)
next i

Dim rng As Range
Set rng = Union(newData(1).Columns(2), newData(1).Columns(3),
newData(2).Columns(2), newData(2).Columns(3), newData(3).Columns(2),
newData(3).Columns(3))

newChart.SeriesCollection.Extend Source:=rng, Rowcol:=xlRows,
CategoryLabels:=True

The only solution I can see now is to rearrange my data in to a new
table and this is not something that I would like to do.

Regards,
Kristina
 
Back
Top