Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default chart.add gives compile error

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/Cha...kChartVBA.html
but I'm baffled as to why charts.add isn't working - anyone have any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default chart.add gives compile error


Your code works fine for me. Note that it will add a separate chart
sheet rather than a chart object on a worksheet. I notice that the "Charts"
method is not capitalized in your code. This is often a sign that you have a
variable, class, or procedure named "charts" and VBA is getting confused
between the two.

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"helpma" wrote in message
...
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/Cha...kChartVBA.html
but I'm baffled as to why charts.add isn't working - anyone have any
ideas?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default chart.add gives compile error

Ah, stupid me - I'd named the module 'Charts' - and like you say, VBA was
getting confused. Changed the module name, and everything works fine. Many
thanks for your help, Rob!

"Rob Bovey" wrote:


Your code works fine for me. Note that it will add a separate chart
sheet rather than a chart object on a worksheet. I notice that the "Charts"
method is not capitalized in your code. This is often a sign that you have a
variable, class, or procedure named "charts" and VBA is getting confused
between the two.

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"helpma" wrote in message
...
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/Cha...kChartVBA.html
but I'm baffled as to why charts.add isn't working - anyone have any
ideas?




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Solver - error - Compile Error Nina Excel Discussion (Misc queries) 0 August 19th 08 09:41 PM
help with this error-Compile error: cant find project or library JackR Excel Discussion (Misc queries) 2 June 10th 06 09:09 PM
How do I get rid of "Compile error in hidden module" error message David Excel Discussion (Misc queries) 4 January 21st 05 11:39 PM
Compile error in hidden module error Melissa Zebrowski Excel Programming 3 February 20th 04 01:29 PM


All times are GMT +1. The time now is 05:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"