Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel chart X values

Status
Not open for further replies.

VBAva

Programmer
Jul 29, 2003
87
IE
hello,
I have a chart with four series and i want to add a fifth. the x values for the new series should be the same as for the others.
If i do not enter the range for the XValues for the new series, the line numbers are used.
i dont know what the cells will be used for the XValues for the first four series, so i just need to be able to say that they are the same

i was thinking something along the lines of this but i cant seem to get the commands just right

newX = ActiveChart.SeriesCollection(1).XValues
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(5).XValues = newX

or
ActiveChart.SeriesCollection(5).XValues = ActiveChart.SeriesCollection(1).XValues


but both of these give errors.

any help would be very welcome
 
The assignment from .XValues is an array not String, although you can assign a string of cell range to it. Try this code:
Dim r As Variant

r = ActiveChart.SeriesCollection(1).XValues

Dim v() As Single, i As Integer
ReDim v(LBound(r) To UBound(r))
For i = LBound(r) To UBound(r)
v(i) = r(i)
Next
ActiveChart.SeriesCollection(2).XValues = v
 
I've not had this problem. An example from a sub I use frequently:

Set DSource = Range(cell.Offset(row1 - 3, 0), cell.Offset(row2 - 3, 0))
activechart.SeriesCollection.Add Source:=DSource

This adds a new series which uses the same XValues range as the ones already on the plot. What chart type is your chart? I think I may have seen this problem occur when there are text values in the new data series, instead of just numbers and blanks.


Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top