ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ChartObjects (https://www.excelbanter.com/excel-programming/430247-chartobjects.html)

Scooter

ChartObjects
 

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



Patrick Molloy

ChartObjects
 


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" wrote in message
...
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



Scooter

ChartObjects
 

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" wrote in message
...
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




Patrick Molloy

ChartObjects
 

how about

?ActiveSheet.ChartObjects(0).Name

"Scooter" wrote in message
...
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" wrote in message
...
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




Andy Pope

ChartObjects
 

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" wrote in message
...
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





All times are GMT +1. The time now is 07:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com