H
helpma
I'm trying to automate chart plotting from data in range(B5:C15), using the
following code:
Dim Chrt As Chart
Set Chrt = charts.Add
With Chrt
.ChartType = xlColumnClustered
.SetSourceData Source:=Sheets("Data").Range("b5:c15"), PlotBy:=xlRows
.HasTitle = True
End With
Running this generates an error message at the charts.add command (Compile
Error: Method or Data Member not Found). If I record a macro using the
chart wizard, then "charts.add" is included in the recorded code (and the
chart is created fine), but if I try to run the recorded macro again, the
same error message occurs.
I can get round this using the "chartobjects.add" routine
With ActiveSheet.ChartObjects.Add _
(Left:=100, Width:=375, Top:=75, Height:=225)
.Chart.SetSourceData Source:=Sheets("data").Range("b5:c15")
.Chart.ChartType = xlXYScatterLines
End With
from http://www.peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.html
but I'm baffled as to why charts.add isn't working - anyone have any ideas?
following code:
Dim Chrt As Chart
Set Chrt = charts.Add
With Chrt
.ChartType = xlColumnClustered
.SetSourceData Source:=Sheets("Data").Range("b5:c15"), PlotBy:=xlRows
.HasTitle = True
End With
Running this generates an error message at the charts.add command (Compile
Error: Method or Data Member not Found). If I record a macro using the
chart wizard, then "charts.add" is included in the recorded code (and the
chart is created fine), but if I try to run the recorded macro again, the
same error message occurs.
I can get round this using the "chartobjects.add" routine
With ActiveSheet.ChartObjects.Add _
(Left:=100, Width:=375, Top:=75, Height:=225)
.Chart.SetSourceData Source:=Sheets("data").Range("b5:c15")
.Chart.ChartType = xlXYScatterLines
End With
from http://www.peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.html
but I'm baffled as to why charts.add isn't working - anyone have any ideas?