In VBA, how can I tell when a chart series point becomes no longer selected

Brass Contributor

When the user selects a point in a chart series (it's a scatter plot), it triggers an EventChart_Select event. In the event code, I change the appearance of the point so if the user looks away from the screen and looks back again, they can still see the point they have selected.

 

When the point is no longer selected, I want to change its appearance back to "normal." Unfortunately, there is no single event that I'm aware of (I'm relatively new to VBA) where this can be done.  If the selection changes because a cell on the worksheet selected, it triggers a Worksheet_SelectionChange event.  If the selection changes because something else on the chart is selected, it triggers another EventChart_Select event.  So if I want to change the appearance of the point, I need to add code in both places. It feels like there should be a better way.  Is there? 

2 Replies

@perkin_warbeck 

You could store the most recently highlighted point in a public variable, and create a "reset" procedure that resets this point. You can then call this from the Worksheet_SelectionChange event procedure and from the Chart_Select event procedure, in the latter case before highlighting a new point if applicable.

The problem is that there is no single event for a selection change. There are two, one for chart and one for the sheet. Which means the reset procedure must be called from two different places. I stopped using global variables in event-driven code because I'm not experienced enough to know how to handle initialization in an event-driven application. So I would probably have reset search the series. That was my original "solution" but I don't like it. It's ugly.