Want to run an event on manually selecting a chart on a sheet

Kevlar1

New Member
Joined
Feb 4, 2015
Messages
3
Hi All, having some issues and don't have any more hair to pull out! I have 31 charts on a sheet and on manually selecting one want to run some script.

I need to be able to use the chart number selected on the sheet. I have played with this for to long and tried using worksheet change and selection change events but no joy. Can anyone give me a leader?

Many thanks in advance for any help.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
You can't just select the chart manually, then run your macro, using ActiveChart to identify the chart?
 
Upvote 0
Thanks for replying, much appreciated. I think the thing im struggling with is where to trigger the script from as struggling with getting it to work from worksheet selectionchange.
 
Upvote 0
Selecting a chart will not fire a worksheet event.

If you're manually selecting the sheet, and it's for your own use, what difference is it if you also then manually run the code?

Or is it for others to use? If the code is in the same workbook, it might be reliable enough to assign a macro to the chart.

Right click on the chart, choose Assign Macro, and select the VBA procedure from the list that pops up.

An example of the code you might write is below. I simply cycled through three chart types so I could watch the charts change as I clicked on them. Application.Caller is the name of whatever triggered the macro, in this case the name of the Shape (ChartObject) that you clicked on to run the code. So the chart that you clicked on is referenced by ActiveSheet.ChartObjects(Application.Caller).Chart.

Code:
Sub DoChart()
  With ActiveSheet.ChartObjects(Application.Caller).Chart
    Select Case .ChartType
      Case xlLineMarkers
        .ChartType = xlColumnClustered
      Case xlColumnClustered
        .ChartType = xlArea
      Case xlArea
        .ChartType = xlLineMarkers
    End Select
  End With
End Sub
 
Upvote 0
Another approach would be to set up chart events in the worksheet so that clicking a chart would trigger the code. This is much more complicated, but much more powerful, because you could perform different actions based on what was selected (an axis, a title, a plotted series). I wrote a tutorial about this recently, Chart Events in Microsoft Excel.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,588
Members
449,039
Latest member
Arbind kumar

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