chats help

S

srinivas

Hi all,

I am Using MS office 2003. I want to create chart using VBA. I have
written the folowing function.

Public Function AddChartSheet(ByVal x As Long, ByVal y As Long, ByVal z
As Long)
Sheet1.Activate
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheet1.Range(Cells(z + 1, 2),
Cells(x - 1, y - 1)), PlotBy:= _
xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet
End Function

and calling this function in my main program. But I am geeting and
error "Method of cells of object _Global Failed".

Can any one suggest.

Regards,
Srinivas
 
R

Robin Hammond

Srinivas,

I haven't tested it but I would guess that you need to qualify the cells
reference, since you have added a chart sheet (which does not have cells).

Try this
ActiveChart.SetSourceData Source:=Sheet1.Range(Sheet1.Cells(z + 1,
2),Sheet1.Cells(x - 1, y - 1)), etc...

Robin Hammond
www.enhanceddatasystems.com
 
J

Jim Cone

Srinivas,
When you add the chart, it becomes the active sheet.
"Cells" refers to the active sheet.
Add "Sheet1." in front of "Cells" (two places).
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"srinivas"
<[email protected]>
wrote in message
Hi all,
I am Using MS office 2003. I want to create chart using VBA. I have
written the folowing function.

Public Function AddChartSheet(ByVal x As Long, ByVal y As Long, _
ByVal z As Long)
Sheet1.Activate
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheet1.Range(Cells(z + 1, 2),
Cells(x - 1, y - 1)), PlotBy:= _
xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet
End Function

and calling this function in my main program. But I am geeting and
error "Method of cells of object _Global Failed".
Can any one suggest.
Regards,
Srinivas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top