Cell to Run Macro

Paul Norris

Board Regular
Joined
Feb 20, 2011
Messages
96
Hi
I am stumped on running my macro; I wish to click on a cell and the Macro should then run, stumbling block is that the cell is pre formulated and need to remain visable so am unable to use buttons, any hints or tips would be great.
Thanks in advance
Paul
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Right click on sheet tab and choose "View Code" and there you will find this worksheet level event code:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" 'Your cell address will come here!
'Dosomething
End If
End Sub

This is default code for worksheet.
 
Upvote 0
Rightclick on the tab with the name of the sheet, chose Display Code, put thi macro in the empty right frame
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$2" Then Call YourMacro
End Sub
This will invoke YourMacro whenever cell A2 is selected.
It could be wise, at the beginning of your macro, put Application.EnableEvents = False and restore "=True" on exit (beware of all possible sub exit); this is "mandatory" if YourMacro de-select and re-select A2.

Bye

PS: taurean was much faster in his response, see above
 
Last edited:
Upvote 0
Right click on sheet tab and choose "View Code" and there you will find this worksheet level event code:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" 'Your cell address will come here!
'Dosomething
End If
End Sub

This is default code for worksheet.

Will give it a try and let you know Thanks
 
Upvote 0
Right click on sheet tab and choose "View Code" and there you will find this worksheet level event code:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" 'Your cell address will come here!
'Dosomething
End If
End Sub

This is default code for worksheet.


Will give it a try and let you know Thanks
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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