Ian -
I think you need to be more specific with Range:
With ActiveChart.SeriesCollection.NewSeries
.Name = "2"
.Values = ActiveSheet.Range(Cells(5, "b"), Cells(5, "l"))
.XValues = ActiveSheet.Range(Cells(length, "b"), Cells(length, "l"))
End With
or with Cells
With ActiveChart.SeriesCollection.NewSeries
.Name = "2"
.Values = ActiveSheet.Range(ActiveSheet.Cells(5, "b"), _
ActiveSheet.Cells(5, "l"))
.XValues = ActiveSheet.Range(ActiveSheet.Cells(length, "b"), _
ActiveSheet.Cells(length, "l"))
End With
- Jon
-------
Jon Peltier, Microsoft Excel MVP
http://www.geocities.com/jonpeltier/Excel/index.html
_______
Ian Mangelsdorf wrote:
Thanks Bill
Ive made the changes but am now getting another @!#$@ error
when I run the sub
Method 'cells' of Object '_Global' fails.
Am I not referencing the worksheet properly?
Sample_no is a name reference in the active worksheet
Sub AddChartObject()
Dim myChtObj As ChartObject
Dim sample_no As Range
Dim length As Integer
Set sample_no = Range("sample_No")
length = 5
For Each cell In sample_no
If cell.Value 0 Then
length = length + 1
End If
Next cell
Set myChtObj = ActiveSheet.ChartObjects.Add _
(Left:=100, Width:=375, Top:=75, Height:=225)
myChtObj.Chart.ChartType = xlXYScatterLines
myChtObj.Activate
With ActiveChart.SeriesCollection.NewSeries
.Name = "2"
.Values = Range(Cells(5, "b"), Cells(5, "l"))
.XValues = Range(Cells(length, "b"), Cells(length, "l"))
End With
End Sub
Cheers
Ian
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!