PC Review


Reply
Thread Tools Rate Thread

ChartObjects

 
 
Scooter
Guest
Posts: n/a
 
      23rd Jun 2009

Why does this work

ActiveSheet.ChartObjects("1020").Activate

but this doesnt

Dim ChartName(12) As String
ChartName(0) = "1020"
I = 0
ActiveSheet.ChartObjects(ChartName(I)).Activate


 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      23rd Jun 2009


works for me, I have a DIM for I too ...

Sub ShowMessage()
Dim ChartName(12) As String
Dim i As Long
ChartName(0) = "Chart 1"
i = 0
ActiveSheet.ChartObjects(ChartName(i)).Activate

End Sub


try
?ActiveSheet.ChartObjects(1).Name
in the immediate window to check that "1020" is correct - i assume so since
you said so, but safe to check



"Scooter" <(E-Mail Removed)> wrote in message
news:88918F5B-EB7F-426E-81F9-(E-Mail Removed)...
> Why does this work
>
> ActiveSheet.ChartObjects("1020").Activate
>
> but this doesnt
>
> Dim ChartName(12) As String
> ChartName(0) = "1020"
> I = 0
> ActiveSheet.ChartObjects(ChartName(I)).Activate
>
>

 
Reply With Quote
 
Scooter
Guest
Posts: n/a
 
      23rd Jun 2009

I get "Run-time error '1004': Application-defined or object-defined error"

"Patrick Molloy" wrote:

>
> works for me, I have a DIM for I too ...
>
> Sub ShowMessage()
> Dim ChartName(12) As String
> Dim i As Long
> ChartName(0) = "Chart 1"
> i = 0
> ActiveSheet.ChartObjects(ChartName(i)).Activate
>
> End Sub
>
>
> try
> ?ActiveSheet.ChartObjects(1).Name
> in the immediate window to check that "1020" is correct - i assume so since
> you said so, but safe to check
>
>
>
> "Scooter" <(E-Mail Removed)> wrote in message
> news:88918F5B-EB7F-426E-81F9-(E-Mail Removed)...
> > Why does this work
> >
> > ActiveSheet.ChartObjects("1020").Activate
> >
> > but this doesnt
> >
> > Dim ChartName(12) As String
> > ChartName(0) = "1020"
> > I = 0
> > ActiveSheet.ChartObjects(ChartName(I)).Activate
> >
> >

>

 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      23rd Jun 2009

how about

?ActiveSheet.ChartObjects(0).Name

"Scooter" <(E-Mail Removed)> wrote in message
news:682D4580-411B-4BF9-849F-(E-Mail Removed)...
> I get "Run-time error '1004': Application-defined or object-defined error"
>
> "Patrick Molloy" wrote:
>
>>
>> works for me, I have a DIM for I too ...
>>
>> Sub ShowMessage()
>> Dim ChartName(12) As String
>> Dim i As Long
>> ChartName(0) = "Chart 1"
>> i = 0
>> ActiveSheet.ChartObjects(ChartName(i)).Activate
>>
>> End Sub
>>
>>
>> try
>> ?ActiveSheet.ChartObjects(1).Name
>> in the immediate window to check that "1020" is correct - i assume so
>> since
>> you said so, but safe to check
>>
>>
>>
>> "Scooter" <(E-Mail Removed)> wrote in message
>> news:88918F5B-EB7F-426E-81F9-(E-Mail Removed)...
>> > Why does this work
>> >
>> > ActiveSheet.ChartObjects("1020").Activate
>> >
>> > but this doesnt
>> >
>> > Dim ChartName(12) As String
>> > ChartName(0) = "1020"
>> > I = 0
>> > ActiveSheet.ChartObjects(ChartName(I)).Activate
>> >
>> >

>>

 
Reply With Quote
 
Andy Pope
Guest
Posts: n/a
 
      24th Jun 2009

Hi,

If you have xl2007, including SP2, then this is a bug, which I have reported
to MS.

If the chartobjects name is a numeric string it appears it gets converted to
a true numeric value and then used to Index the chartobjects collection.
So it is actually treated as if you had written this,

ActiveSheet.ChartObjects(1020).Activate

Only work around is to use AlphaNumeric names for your chart objects.

Cheers
Andy
--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
"Scooter" <(E-Mail Removed)> wrote in message
news:88918F5B-EB7F-426E-81F9-(E-Mail Removed)...
> Why does this work
>
> ActiveSheet.ChartObjects("1020").Activate
>
> but this doesnt
>
> Dim ChartName(12) As String
> ChartName(0) = "1020"
> I = 0
> ActiveSheet.ChartObjects(ChartName(I)).Activate
>
>


 
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
F1 help for ChartObjects John Microsoft Excel Programming 1 21st Oct 2006 02:36 AM
ChartObjects =?Utf-8?B?U2NvdHQ=?= Microsoft Excel Programming 1 30th Jun 2006 12:23 AM
Problems with ChartObjects pwermuth Microsoft Excel Programming 5 12th Jul 2005 11:19 PM
Not allow selection of chartobjects ? Gunnar Johansson Microsoft Excel Charting 0 8th May 2005 01:40 PM
ChartObjects Nick Microsoft Excel Programming 2 19th Aug 2004 12:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:02 AM.