auto-run a macro when an entry is made on the worksheet


Posted by greg on January 10, 2002 6:23 AM

How do I automatically run a macro every time an entry is made on the worksheet?

Posted by DK on January 10, 2002 6:48 AM

Right click the worksheet tab in question and choose View Code. Try something like this:-

Private Sub Worksheet_Change(ByVal Target As Range)
'Target is the range that has been changed by the user. It could refer to
'one or more cells.
MsgBox "Wow, cell " & Replace(Target.Address, "$", "") & " was changed!"

End Sub

Hope that helps,

D.

Posted by Barrie Davidson on January 10, 2002 6:49 AM

Insert your code in the worksheet's code (you can access this by right clicking on the worksheet's tab and selecting View Code). Make sure your code is in the "Worksheet_Change" part (select this by clicking on the drop down box on the right hand side of the code window, right beside the drop down box that should have "Worksheet" in it). This box will default to "Selection Change" when you first view the sheet's code. You can delete that Sub.

Hopefully I've explained this well enough to help you :)

BarrieBarrie Davidson



Posted by Sam S on January 10, 2002 8:22 PM


Greg
There are some examples on this site which are helpful.

http://www.lacher.com/toc.htm

Sam S