how to call a macro from a worksheet event?

  • Thread starter Thread starter lopsided
  • Start date Start date
L

lopsided

Dear all,

I need to call a macro when data is pasted into a particular cell on
particular worksheet. I am having a few problems with this, any hel
would be greatly appretiated.

Many thanks,

To
 
Use a worksheet change event by right click on sheet tab>view code>insert
this>modify>save
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$F$1" Then Exit Sub
Call mysub
End Sub
Sub mysub()
MsgBox "Hi"
End Sub
 
Hi Don,

That worked fine - i didnt realise this code needed to go in the
worksheet code, i kept trying to put coding in a separate module!

Many thanks,

Tom
 
glad to help. UDF functions need to go in a general module. In the
ThisWorkbook module there is code that will act of EACH sheet in the
workbook. Take a look.
 
You need to use the worksheet change event (doubleclick the sheet name
in VB Editor) :-

'------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$A$1" Then MsgBox ("change")
End Sub
'-------------------------------------------------
 
Back
Top