How can I automatically execute a macro ASA data are entered in a cell ?

R

Rasha

Hello world,

How can I AUTOMATICALLY execute My_macro( ) each time a data is entered in a
cell ?
I wanna the event "entering data in a cell" call my macro. How can I do it ?

Thanks for help.
 
G

Gord Dibben

Rasha

One specific cell...

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo enditall
If Target.Address = "$A$1" Then
MsgBox "click ok to make me leave"
End If
enditall:
End Sub

Column A cells...........

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo enditall
If Target.Cells.Column = 1 Then
n = Target.Row
If Excel.Range("A" & n).Value <> "" Then
MsgBox "click ok to make me leave"
End If
End If
enditall:
End Sub

In both cases substitute your macro name for the MsgBox line. Either of these
go into the worksheet. Right-click on sheet tab and "View Code" to paste in.

Note: you can't have both at the same time.

Gord Dibben XL2002
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top