How do I RUN A MACRO AT THE POINT OF CELL SELECTION?

Bikeit

New Member
Joined
May 7, 2002
Messages
5
Can anybody tell me how I can make a macro run automatically at the point a user selects a cell on the worksheet before entering any data whether it is blank or not?

Thanks in advance.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
On 2002-05-13 07:11, Bikeit wrote:
Can anybody tell me how I can make a macro run automatically at the point a user selects a cell on the worksheet before entering any data whether it is blank or not?

Thanks in advance.

Right Click on the Sheets tab you want to
have the macro run in.

Insert/paste this code in;

<pre/>
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" Then
RunMyMacro
End If
End Sub
</pre>

This is a Sheet Event procedure and runs when
there is a change in the sheets selection.
In this case a Macro Named [RunMyMacro] is
called when ever A1 is selected, A1 being
the Target to watch for in this example.
 
Upvote 0
Ivan, thanks for the reply. I know how to that bit, but it requires me to enter something into the cell first. What I need to do is run the macro at the point of selecting the cell with the mouse pointer.
Pehaps it's daft as pointed out by friendly asfgfhgabcdsillyperson or whoever.
 
Upvote 0
On 2002-05-13 08:17, Bikeit wrote:
...it requires me to enter something into the cell first. What I need to do is run the macro at the point of selecting the cell with the mouse pointer.

Isn't that just what SelectionChange does?
Try
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
MsgBox "A"
End Sub

And you'll see that the msgbox appears as soon as you just change the selection.
 
Upvote 0
On 2002-05-13 08:17, Bikeit wrote:
Ivan, thanks for the reply. I know how to that bit, but it requires me to enter something into the cell first. What I need to do is run the macro at the point of selecting the cell with the mouse pointer.
Pehaps it's daft as pointed out by friendly asfgfhgabcdsillyperson or whoever.

Did you try it ?? code fires when the cell
A1 is selected via mouse selection or keying
over to it.
 
Upvote 0
Cheers guys, thats sorted things out.
Your help has been very much appreciated.
Ivan..thanks for the email correspondence.
:smile:
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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