Chartobjects count method

DieHard

New Member
Joined
Nov 28, 2011
Messages
1
Hi,

I've a worksheet with several rows of two charts. I try to delete and add new ones, but therefore I need their names. So what I do is, each time I rename all these charts in the following way:

Code:
For i = 1 To ActiveSheet.ChartObjects.Count
ActiveSheet.ChartObjects(i).Name = i
Next i

Problem:
I can have the following situation (in Chart names):
1 2
3 4
. . (none)
5 6

Then I add two charts at 'line' 3 and I change ALL the chart names into a string (not a number). And then I run the given For loop in order to achieve this:
1 2
3 4
5 6
7 8

But what I get is:
1 2
3 4
7 8
5 6

It seems as if Excel remembers where I inserted them...

Anyone have a clue on what I could try to come around this?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
It's not clear what you wish to do here. However, the order of the charts is not important if you refer to them by name. But, if you have to then this code will activate each chart in order.

Code:
Option Explicit
Sub test()
    Dim i
    For i = 1 To ActiveSheet.ChartObjects.Count
       ActiveSheet.ChartObjects(ActiveSheet.ChartObjects(i).Name).Activate
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top