Invoke Macro on entering data in column

G

GeorgeR

Hi all
Getting a bit frustrated with this. Using Excel 2007.
I have a worksheet "CallList" with Column P named "Lead"
I am attempting to invoke a "Sort"macro automatically that would be
triggered by the insertion of data into Column P. Unsure of code to call
macro from VBA. I think its should be invoked from the worksheet module. This
macro will be stored in Personal workbook but I need to be able to import it
into a number of different workbooks each week.
Any help would be appreciated.

Thanks very much!!
 
G

Gary''s Student

Insert the following event macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set p = Range("P:p")
If Intersect(t, p) Is Nothing Then Exit Sub
Application.EnableEvents = False
Call mySort
Application.EnableEvents = True
End Sub


mySort can be in either the worksheet code area or a public module.
 
G

GeorgeR

Hi GS
Thanks for the input. However after pasting your code I get a variable not
defined at "t" "set t as target.
 
R

Rick Rothstein

Better yet would have been to leave the Option Explicit statement in and
just declare the variables the Gary''s Student left out; namely, Dim both t
and p as Range.
 
G

GeorgeR

Thanks Rick
Will give it a try.

Rick Rothstein said:
Better yet would have been to leave the Option Explicit statement in and
just declare the variables the Gary''s Student left out; namely, Dim both t
and p as Range.
 

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