#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Chart Code

Hi I am getting frustrated with the code for the chart as below.
I want the chart series data source to change depending on a checkbox
linked to a cell. However I seem to have a problem with the line that
changes the values. (I recorded the original code from a macro). I have
tried naming the series collection by number but this doesn't work
either. When I step through the code and get to either of the lines
that say " ......values = "=R" then I get a run time error 1004
application or user defined error or a run time error 438 object does
not support this property or method.


Sheets("chart").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select

If ActiveSheet.Range("a3") = True Then
ActiveChart.seriescollection("HAMILTON").Select
ActiveChart.seriescollection("HAMILTON").values = "=R28C4:R34C4"
Else: ActiveChart.seriescollection("HAMILTON").values =
"=R2C2:R20C2"

I'd appreciate any advice anyone can give me as to where I am going
wrong. Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Chart Code

Rather than using code, you could use a dynamic range.

Create a named range with a formula that returns the range depending on
the check box value:
=INDIRECT(IF(checkbox,"rng_a","rng_b"))

where
- "checkbox" is the cell that contains either TRUE or FALSE depending
on the
- rng_a is the range name for range R28C4:R34C4
- rng_b is the range name for range R2C2:R20C2

then use this range name in the definition of the data for your chart.

For a good introduction to using dynamic named ranges:
http://www.ozgrid.com/Excel/DynamicRanges.htm
http://www.glencoe.com/ps/computered...?articleId=376

keri a écrit :

Hi I am getting frustrated with the code for the chart as below.
I want the chart series data source to change depending on a checkbox
linked to a cell. However I seem to have a problem with the line that
changes the values. (I recorded the original code from a macro). I have
tried naming the series collection by number but this doesn't work
either. When I step through the code and get to either of the lines
that say " ......values = "=R" then I get a run time error 1004
application or user defined error or a run time error 438 object does
not support this property or method.


Sheets("chart").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select

If ActiveSheet.Range("a3") = True Then
ActiveChart.seriescollection("HAMILTON").Select
ActiveChart.seriescollection("HAMILTON").values = "=R28C4:R34C4"
Else: ActiveChart.seriescollection("HAMILTON").values =
"=R2C2:R20C2"

I'd appreciate any advice anyone can give me as to where I am going
wrong. Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Chart Code

You can only apply a source range to the entire chart with SetSourceData. To
link cells to individual series the only way AFAIK is by parsing and writing
the reference in the Series formula, for y-values in the third argument.
Typically, though not necessarily, that'd be between the 2nd & 3rd commas.
Then replace and insert -

rng.Address(, , , True))

If you want to apply 'hard' values (not linked to cells) you could probably
do -
mySeries.values = Evaluate(rng.Address)

There's an absolute max 255 characters limit and including an extra
allowance of 1 per value.

A different approach might be to use dynamic names which perhaps wouldn't
involve any code at all. This could be set up with different offsets from an
anchor cell depending on the value of the checkbox's linked cell.

Regards,
Peter T

"keri" wrote in message
ups.com...
Hi I am getting frustrated with the code for the chart as below.
I want the chart series data source to change depending on a checkbox
linked to a cell. However I seem to have a problem with the line that
changes the values. (I recorded the original code from a macro). I have
tried naming the series collection by number but this doesn't work
either. When I step through the code and get to either of the lines
that say " ......values = "=R" then I get a run time error 1004
application or user defined error or a run time error 438 object does
not support this property or method.


Sheets("chart").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select

If ActiveSheet.Range("a3") = True Then
ActiveChart.seriescollection("HAMILTON").Select
ActiveChart.seriescollection("HAMILTON").values = "=R28C4:R34C4"
Else: ActiveChart.seriescollection("HAMILTON").values =
"=R2C2:R20C2"

I'd appreciate any advice anyone can give me as to where I am going
wrong. Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Chart Code

You could use dynamic ranges, as others have suggested, or you could
properly reference the ranges for the .Values property of the series by
including the sheet name.

ActiveChart.seriescollection("HAMILTON").values = "=Sheet1!R28C4:R34C4"

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"keri" wrote in message
ups.com...
Hi I am getting frustrated with the code for the chart as below.
I want the chart series data source to change depending on a checkbox
linked to a cell. However I seem to have a problem with the line that
changes the values. (I recorded the original code from a macro). I have
tried naming the series collection by number but this doesn't work
either. When I step through the code and get to either of the lines
that say " ......values = "=R" then I get a run time error 1004
application or user defined error or a run time error 438 object does
not support this property or method.


Sheets("chart").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select

If ActiveSheet.Range("a3") = True Then
ActiveChart.seriescollection("HAMILTON").Select
ActiveChart.seriescollection("HAMILTON").values = "=R28C4:R34C4"
Else: ActiveChart.seriescollection("HAMILTON").values =
"=R2C2:R20C2"

I'd appreciate any advice anyone can give me as to where I am going
wrong. Thanks.



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
Chart Object VB Code MS[_2_] Charts and Charting in Excel 2 March 6th 07 11:41 AM
Chart code keri Excel Programming 4 December 15th 06 02:29 PM
VBA code for chart chris[_16_] Excel Programming 3 November 16th 05 04:32 PM
Flow chart of code? Is there a way to produce a graphical flow chart? Craigm[_40_] Excel Programming 8 August 23rd 05 10:04 AM
Please Help With Chart Code WayneK[_7_] Excel Programming 2 August 9th 05 04:48 PM


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