I'm getting an error when I try to set the XValues for a chart in my excel worksheet.
The chart shows up fine and the new series adds fine though when I try to set the XValues the below error occurs
'Unable to set the Xvalues property of the Series Class' 1004
My Code is below. Can anyone see anything wrong with it? This could be a floor in my understanding of the chart object. I don't want to be selecting charts and working on an activechart because I'll have several in the one worksheet.
Dim Chart1 As Chart
Set Chart1 = charts.Add
'
Set Chart1 = Chart1.Location(Where:=xlLocationAsObject, Name:="Sheet1")
With Chart1
.ChartType = xlLine
End With
'
'works correctly
Chart1.SeriesCollection.NewSeries
'I get the error when reaching the line below
Chart1.SeriesCollection(1).XValues = "=Sheet2!R334C27:R334C31"
Bookmarks