I should know this, but... How to run macro when cell is activated


Posted by Pasi Vartiainen on November 06, 2000 3:04 AM

This questin is maybe asked multiple times, but I am unable to find it from here. I have tried seach, but nothing occurres.

I want macro to run every time when cell is activated. So when user points cell with mouse, or shifts cell with arrow or uses page up/down key, macro is runned.

Macro which I want run is ready, but I dont know how to run it when cell is activated
----
parametri = ActiveCell.Value
Workbooks("help_texts").Activate
Sheets("help").Open
For i = 1 To 300
If Cells(i, 1).Value = parametri Then
Cells(i, 2).Value = parametri
i = 299
End If
Next
Workbooks("nedprice").Activate
Shapes("TextBox1").Value = parametri
----

Hope that some-one can help me.
Pasi Vartiainen

Posted by JAF on November 06, 2000 3:35 AM

You need to place the following code in the Sheet Object:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$5" Then
'your macro here
End If
End Sub

This will run specified code when A5 (in this example) is selected.

HTH
JAF



Posted by Pasi Vartiainen on November 06, 2000 5:51 AM

Thaks JAF

Many thanks, it helped, and worked.