VBA and charts

G

Guest

Hi all. I'm having trouble working with charts in Excel using Visual basic.

What I'm trying to do is take an embedded chart that is selected, copy and paste it, then select the original chart.

The trouble I'm having is that I just can't get visual basic to tell me the index of the active chart!

Msgbox ActiveChart.Index
returns an "Method 'Index' of object '_Chart' failed" error

Msgbox ActiveChart.name
works, but returns "charts Chart 12" for example. This would be fine if I could then use this to refer to the chart later, but I think the extra "charts" is throwing it off

Can anyone offer any help

Eric
 
D

Debra Dalgleish

This gives the number for the chartObject --

Sub GetIndex()
Dim chObj As ChartObject
Set chObj = ActiveChart.Parent

Debug.Print ActiveSheet _
.ChartObjects(chObj.Name).Index

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top