PC Review


Reply
 
 
keri
Guest
Posts: n/a
 
      15th Dec 2006
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 With Quote
 
 
 
 
bdarbonneau@gmail.com
Guest
Posts: n/a
 
      15th Dec 2006
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.


 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      15th Dec 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      15th Dec 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      15th Dec 2006
Or you could simply use the value of the option buttons' linked cell in the
definition of the dynamic range, and not use any of this code.

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


"Martin Fishlock" <(E-Mail Removed)> wrote in message
news:E28CD7A3-07AC-41A2-8C29-(E-Mail Removed)...
> Keri,
>
> The following changes a chart called 'Chart 1' and with the click of a
> check
> box you can show or hide a series line.
>
> There is also the option for dealing with the legend.
>
> If you have 26 series on the chart then you just have 26 check boxes and
> run
> the code.
>
> If you have radio buttons instead and just want to display one series then
> you will have to manage the switch over by using a global variable to
> remeber
> which one is showing.
>
>
>
> Option Explicit
> 'legend must be the same number as the series
> Private Sub SwitchSeriesLine(seriesLine As Integer, bShowIt As Boolean,
> bHaveLegend)
> Dim linestyle As XlLineStyle
> Dim linecolor As XlColorIndex
> Dim fontcolor As XlColorIndex
> Dim fontbckgrd As Long
>
> If bShowIt Then
> linestyle = xlContinuous
> linecolor = xlAutomatic
> fontcolor = xlAutomatic
> fontbckgrd = xlBackgroundAutomatic
> Else
> linestyle = xlNone
> linecolor = xlNone
> fontcolor = 2
> fontbckgrd = xlBackgroundTransparent
> End If
> With Worksheets(1).ChartObjects("Chart 1").chart
> With .SeriesCollection(seriesLine)
> .Border.linestyle = linestyle
> .MarkerBackgroundColorIndex = linecolor
> .MarkerForegroundColorIndex = linecolor
> End With
> If bHaveLegend Then
> With .Legend.LegendEntries(seriesLine).Font
> .ColorIndex = fontcolor
> .Background = fontbckgrd
> End With
> End If
> End With
>
> End Sub
>
> Private Sub CheckBox1_Click()
> SwitchSeriesLine 1, Me.CheckBox1.Value, True
> End Sub
>
> Private Sub CheckBox2_Click()
> SwitchSeriesLine 2, Me.CheckBox2.Value, True
> End Sub
>
> Private Sub CheckBox3_Click()
> SwitchSeriesLine 3, Me.CheckBox3.Value, True
> End Sub
>
> --
> Hope this helps
> Martin Fishlock
> Please do not forget to rate this reply.
>
>
> "keri" wrote:
>
>> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chart Error when using Chart Line - Column on 2 Axes in vba code =?Utf-8?B?Sm9obg==?= Microsoft Excel Programming 2 3rd Aug 2007 01:42 PM
VBA code for Chart homescu@cs.ucsb.edu Microsoft Excel Discussion 1 17th Nov 2005 04:24 AM
VBA code for chart chris Microsoft Excel Programming 3 16th Nov 2005 04:32 PM
Re: Flow chart of code? Is there a way to produce a graphical flow chart? Trevor Shuttleworth Microsoft Excel Programming 0 22nd Aug 2005 10:31 PM
Re: Code chart Tushar Mehta Microsoft Excel Charting 0 17th Jul 2003 04:21 PM


Features
 

Advertising
 

Newsgroups
 


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