Running Macro using a formula


Posted by Jack Terriman on March 23, 2000 12:12 PM

How can I run a macro by using a formula?
If I use a if statement, if cell a1 is greater than 2.
Run macro1.



Posted by Celia on March 23, 2000 1:54 PM


Jack
A macro cannot be run from a worksheet formula.

However, you could do with a macro in the worksheet’s event handler module :-

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$A$1" Then
If Range("A1").Value > 2 Then
Call macro1
End If
End If
End Sub

This macro would be activated automatically when the value of cell A1 changes.
If macro1 is not in the same workbook, the code that calls it would need to be :
Application.Run “Workbook Name.xls!macro1”

Celia