PC Review


Reply
Thread Tools Rate Thread

Changing Chart SourceData in VBA

 
 
JimPNicholls
Guest
Posts: n/a
 
      7th May 2004
Excel 97.

Can anyone spot where I'm going wrong? I'm trying to
change the source data in code so it only shows upto the
last cell that has a value in it. My code at the mo is..

Dim intActiveCell As Integer
Dim strCell As String
Dim strrange As String

Sheets("Financial Tracker").Select
Range("C13").Select

If ActiveCell <> "" Then
Do Until ActiveCell.Value = ""
ActiveCell.Offset(0, 1).Select
Loop
End If
ActiveCell.Offset(0, -1).Select
'Selection.End(xlLeft).Select
strCell = "R" & ActiveCell.Row & "C" & ActiveCell.Column


Sheets("Graphs").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(3).Values = "='Financial
Tracker'!R13C2: & strCell"


It works fine until the last line where it falls over
with "Object variable......"message. Can this be done in
code?

 
Reply With Quote
 
 
 
 
Andy Pope
Guest
Posts: n/a
 
      7th May 2004
Hi Jim,

Try revising the last line., looks like the variable strCell is inside
the quotes.

ActiveChart.SeriesCollection(3).Values _
= "='Financial Tracker'!R13C2:" & strCell

Cheers
Andy

JimPNicholls wrote:

> Excel 97.
>
> Can anyone spot where I'm going wrong? I'm trying to
> change the source data in code so it only shows upto the
> last cell that has a value in it. My code at the mo is..
>
> Dim intActiveCell As Integer
> Dim strCell As String
> Dim strrange As String
>
> Sheets("Financial Tracker").Select
> Range("C13").Select
>
> If ActiveCell <> "" Then
> Do Until ActiveCell.Value = ""
> ActiveCell.Offset(0, 1).Select
> Loop
> End If
> ActiveCell.Offset(0, -1).Select
> 'Selection.End(xlLeft).Select
> strCell = "R" & ActiveCell.Row & "C" & ActiveCell.Column
>
>
> Sheets("Graphs").Select
> ActiveSheet.ChartObjects("Chart 1").Activate
> ActiveChart.ChartArea.Select
> ActiveChart.SeriesCollection(3).Values = "='Financial
> Tracker'!R13C2: & strCell"
>
>
> It works fine until the last line where it falls over
> with "Object variable......"message. Can this be done in
> code?
>


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
 
Reply With Quote
 
JimPNicholls
Guest
Posts: n/a
 
      7th May 2004
Andy

Thanks for the quick reply. I've tried that but I'm still
getting the following error message "Run-Time error'1004'
MEthod 'SeriesCollection' of object ' _Chart' failed. Any
ideas?






>-----Original Message-----
>Hi Jim,
>
>Try revising the last line., looks like the variable

strCell is inside
>the quotes.
>
>ActiveChart.SeriesCollection(3).Values _
> = "='Financial Tracker'!R13C2:" & strCell
>
>Cheers
>Andy
>
>JimPNicholls wrote:
>
>> Excel 97.
>>
>> Can anyone spot where I'm going wrong? I'm trying to
>> change the source data in code so it only shows upto

the
>> last cell that has a value in it. My code at the mo is..
>>
>> Dim intActiveCell As Integer
>> Dim strCell As String
>> Dim strrange As String
>>
>> Sheets("Financial Tracker").Select
>> Range("C13").Select
>>
>> If ActiveCell <> "" Then
>> Do Until ActiveCell.Value = ""
>> ActiveCell.Offset(0, 1).Select
>> Loop
>> End If
>> ActiveCell.Offset(0, -1).Select
>> 'Selection.End(xlLeft).Select
>> strCell = "R" & ActiveCell.Row & "C" & ActiveCell.Column
>>
>>
>> Sheets("Graphs").Select
>> ActiveSheet.ChartObjects("Chart 1").Activate
>> ActiveChart.ChartArea.Select
>> ActiveChart.SeriesCollection(3).Values

= "='Financial
>> Tracker'!R13C2: & strCell"
>>
>>
>> It works fine until the last line where it falls over
>> with "Object variable......"message. Can this be done

in
>> code?
>>

>
>--
>
>Andy Pope, Microsoft MVP - Excel
>http://www.andypope.info
>.
>

 
Reply With Quote
 
Andy Pope
Guest
Posts: n/a
 
      7th May 2004
Has the chart actually got 3 data series?

The error appears for me if I try it on a chart with only 2 data series.

Cheers
Andy


JimPNicholls wrote:

> Andy
>
> Thanks for the quick reply. I've tried that but I'm still
> getting the following error message "Run-Time error'1004'
> MEthod 'SeriesCollection' of object ' _Chart' failed. Any
> ideas?
>
>
>
>
>
>
>
>>-----Original Message-----
>>Hi Jim,
>>
>>Try revising the last line., looks like the variable

>
> strCell is inside
>
>>the quotes.
>>
>>ActiveChart.SeriesCollection(3).Values _
>> = "='Financial Tracker'!R13C2:" & strCell
>>
>>Cheers
>>Andy
>>
>>JimPNicholls wrote:
>>
>>
>>>Excel 97.
>>>
>>>Can anyone spot where I'm going wrong? I'm trying to
>>>change the source data in code so it only shows upto

>
> the
>
>>>last cell that has a value in it. My code at the mo is..
>>>
>>>Dim intActiveCell As Integer
>>>Dim strCell As String
>>>Dim strrange As String
>>>
>>>Sheets("Financial Tracker").Select
>>>Range("C13").Select
>>>
>>>If ActiveCell <> "" Then
>>>Do Until ActiveCell.Value = ""
>>>ActiveCell.Offset(0, 1).Select
>>>Loop
>>>End If
>>>ActiveCell.Offset(0, -1).Select
>>>'Selection.End(xlLeft).Select
>>>strCell = "R" & ActiveCell.Row & "C" & ActiveCell.Column
>>>
>>>
>>>Sheets("Graphs").Select
>>>ActiveSheet.ChartObjects("Chart 1").Activate
>>> ActiveChart.ChartArea.Select
>>> ActiveChart.SeriesCollection(3).Values

>
> = "='Financial
>
>>>Tracker'!R13C2: & strCell"
>>>
>>>
>>>It works fine until the last line where it falls over
>>>with "Object variable......"message. Can this be done

>
> in
>
>>>code?
>>>

>>
>>--
>>
>>Andy Pope, Microsoft MVP - Excel
>>http://www.andypope.info
>>.
>>


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
 
Reply With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      8th May 2004
Jim -

You can also do this without VBA, using dynamic ranges. I have a few
examples and a lot of links:

http://peltiertech.com/Excel/Charts/Dynamics.html

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

JimPNicholls wrote:

> Excel 97.
>
> Can anyone spot where I'm going wrong? I'm trying to
> change the source data in code so it only shows upto the
> last cell that has a value in it. My code at the mo is..
>
> Dim intActiveCell As Integer
> Dim strCell As String
> Dim strrange As String
>
> Sheets("Financial Tracker").Select
> Range("C13").Select
>
> If ActiveCell <> "" Then
> Do Until ActiveCell.Value = ""
> ActiveCell.Offset(0, 1).Select
> Loop
> End If
> ActiveCell.Offset(0, -1).Select
> 'Selection.End(xlLeft).Select
> strCell = "R" & ActiveCell.Row & "C" & ActiveCell.Column
>
>
> Sheets("Graphs").Select
> ActiveSheet.ChartObjects("Chart 1").Activate
> ActiveChart.ChartArea.Select
> ActiveChart.SeriesCollection(3).Values = "='Financial
> Tracker'!R13C2: & strCell"
>
>
> It works fine until the last line where it falls over
> with "Object variable......"message. Can this be done in
> code?
>


 
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
Dynamic sourcedata when copying chart within sheet Josip.2000@gmail.com Microsoft Excel Charting 3 11th Jun 2008 03:37 PM
SourceData of a chart black_sun@email.it Microsoft Excel Programming 3 18th Nov 2007 04:18 PM
Excel/chart/sourcedata - should let me set the left or right axis =?Utf-8?B?YmVsb2hscw==?= Microsoft Excel Charting 1 19th Jun 2006 10:43 PM
Read SourceData from Chart =?Utf-8?B?RmVybmFuZG8=?= Microsoft Excel Programming 3 9th Aug 2005 04:46 AM
chart with changing data source interactive chart Feketik Microsoft Excel Charting 2 19th Mar 2004 09:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:14 PM.