Running a macro


Posted by Nilton on January 15, 2002 10:47 AM

Hello all!
I need to know how to run a macro (or VB code)from a cell, for example in a IF statement.
Lets say IF(A1=1,run the macro,""), how will be the syntax to "run the macro" or a code ?
Thanks a lot,
Nilton

Posted by Tom Morales on January 15, 2002 11:33 AM

Nilton - Open up your sheet's module (right click the sheet tab, and select "view code"). Insert code something like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" Then woj
End Sub

In this case, "woj" is the name of the macro you want to run, presumably in the same workbook.
Tom

Posted by Nilton on January 16, 2002 6:15 AM

Thank you, but I would like also to run the macro from the "IF", like if(A1=2, RUN MACRO, ""), can i do it!

Thanks so far,
Nilton



Posted by Tom Morales on January 16, 2002 11:14 AM

Sorry, Nilton. I misread your request.
Try
Private Sub Worksheet_Change(ByVal Target As Range)
If (Target.Value = 1) And (Target.Address = "$A$1") Then woj
End Sub
Tom