Finding and Selecting Charts in a Workbook

peterhay

New Member
Joined
May 1, 2007
Messages
26
Hi

I have a workbook that contains multiple charts on multiple tabs, each are name uniquely.

I want a way in VBA of being able to input a Chart name e.g. "Chart 1" and then having Excel automatically find the tab that the Chart is on, select that tab, and select the Chart. This is so I can then auto copy and paste the chart into Word (I already have the code working for that).

Any help on this would be much appreciated.

Thanks
Peter
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address <> "$A$1" Then Exit Sub
    Dim Sh As Worksheet
    Dim Ch As ChartObject
    For Each Sh In ThisWorkbook.Worksheets
        For Each Ch In Sh.ChartObjects
            If Ch.Name = Target.Value Then
                Sh.Activate
                Ch.Select
                Exit Sub
            End If
        Next Ch
    Next Sh
End Sub

The code assumes the chart's name is in A1 on the active sheet. Adjust to suit.
 
Upvote 0

Forum statistics

Threads
1,203,622
Messages
6,056,340
Members
444,861
Latest member
B4you_Andrea

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