Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Drawing Charts with VBA


Straight line charts work fine using VBA, but I couldn't get Stock charts to
work at all.
I used the following code:

Charts.Add
ActiveChart.ChartType = xlStockHLC
etc.
etc.


When running the code I get the following error message -

Run-time error '1004'

Method 'ChartType' of object '_Chart' failed.

When debugging, the line "ActiveChart.ChartType = xlStockHLC" is highlighted
in yellow and the values on both sides of the = sign are different. The left
side (ActiveChart.ChartType) = 55 and the right side (xlStockHLC) = 81.

Why would this happen with an assignment of chart type?

Best regards,
Fred


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Drawing Charts with VBA

It would mean the assignment was not completed and the activechart is still
of charttype 55. On the right side, the constant xlStockHLC still retains
its value (apparently of 81)

--
Regards,
Tom Ogilvy

"Fred Russell" wrote in message
...

Straight line charts work fine using VBA, but I couldn't get Stock charts

to
work at all.
I used the following code:

Charts.Add
ActiveChart.ChartType = xlStockHLC
etc.
etc.


When running the code I get the following error message -

Run-time error '1004'

Method 'ChartType' of object '_Chart' failed.

When debugging, the line "ActiveChart.ChartType = xlStockHLC" is

highlighted
in yellow and the values on both sides of the = sign are different. The

left
side (ActiveChart.ChartType) = 55 and the right side (xlStockHLC) = 81.

Why would this happen with an assignment of chart type?

Best regards,
Fred




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Drawing Charts with VBA

Tom,

How do I fix this?

Best regards,
Fred


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Drawing Charts with VBA

have the macro completely build the line chart, then change it to a stock
chart.

If you don't meet all the required criteria to have a stock chart, you will
get an error.

A test would be to run the macro to build the complete chart. Then try to
change the chart type manually. If you succeed, that would be a good
indication that you can do it with code as well.

--
Regards,
Tom Ogilvy

"Fred Russell" wrote in message
...
Tom,

How do I fix this?

Best regards,
Fred




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Drawing Charts with VBA

Thanks Tom

FYI the problem with the ChartType was that even though the macro recorder
in excel records the order as:

Charts.Add
ActiveChart.ChartType = xlStockHLC
ActiveChart.SetSourceData Source:=Range("GraphTable"), PlotBy:=xlColumns

for certain chart types (Stock charting in particular) the data source has
to appear before the ChartType
i.e.

Charts.Add
ActiveChart.SetSourceData Source:=Range("GraphTable"), PlotBy:=xlColumns
ActiveChart.ChartType = xlStockVHLC

after making that correction it worked fine.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Drawing Charts with VBA

That's what I was driving at. I guess I should have said order is important
and the macro recorder doesn't always get it right.

--
Regards,
Tom Ogilvy

"Fred Russell" wrote in message
...
Thanks Tom

FYI the problem with the ChartType was that even though the macro recorder
in excel records the order as:

Charts.Add
ActiveChart.ChartType = xlStockHLC
ActiveChart.SetSourceData Source:=Range("GraphTable"), PlotBy:=xlColumns

for certain chart types (Stock charting in particular) the data source has
to appear before the ChartType
i.e.

Charts.Add
ActiveChart.SetSourceData Source:=Range("GraphTable"), PlotBy:=xlColumns
ActiveChart.ChartType = xlStockVHLC

after making that correction it worked fine.




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
drawing org charts Maniv Excel Worksheet Functions 1 December 30th 09 11:30 PM
Drawing Objects disappear from charts Dave Charts and Charting in Excel 2 February 19th 08 05:32 PM
Drawing Order of Data Series on Charts Eddie McGlone Charts and Charting in Excel 1 September 6th 07 04:08 PM
why don't my drawing tools work in my charts usgsed Charts and Charting in Excel 1 October 31st 06 01:41 PM
Problem drawing lines on charts Susan Lambert Charts and Charting in Excel 7 December 13th 04 08:29 AM


All times are GMT +1. The time now is 05:03 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"