VBA to select a cell relative to a chart

reece1984

New Member
Joined
May 15, 2012
Messages
18
Hi All,

I have inserted macros to zoom to a chart when the chart is selected and then zoom out when it is selected again using an IF formula. The problem is that when trying to selecting the chart for the second time, it doesnt register because the chart is already selected. So the only way to select it and therefore zoom out again is to select somewhere else and then select the chart again.

The solutions that I have in mind, but do not know how to do them is either to have the macro finish by selecting a cell that is relative to the chart. Meaning that it can be selected again without zooming away.

Or have the macro end by selecting a regular cell such as A1 but not have the view shift to that newly selected cell.

Can anybody please help me implement one of these options?

Thanks very much.

J
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
To select the cell that lies under the upper-left corner of the chart, try...

Code:
ActiveSheet.ChartObjects("Chart 1").TopLeftCell.Select
 
Upvote 0
Domenic,

Thanks very much, that's perfect.

I've now realised that the same functionality with other objects would be useful. Could you tell me how to select a cell relative to another object such as a button?

I've tried this but it doesnt seem to work.

'ActiveSheet.Shapes.Range(Array("button_1")).TopLeftCell.Select

thanks

J
 
Upvote 0
That's because the Range property of the Shapes collection returns a ShapeRange, and TopLeftCell is not a property of a ShapeRange. Instead, use the Item method of the Shapes collection...

Code:
ActiveSheet.Shapes.Item("Button_1").TopLeftCell.Select

or

Code:
ActiveSheet.Shapes("Button_1").TopLeftCell.Select
 
Upvote 0

Forum statistics

Threads
1,203,521
Messages
6,055,890
Members
444,831
Latest member
iceonmn

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