View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Run Macros from an IF statement within a formula

Not from within a formula but you can use sheet event code.

Assuming you had a formula in A1 that reads =IF(B1="","",B1)

Private Sub Worksheet_Calculate()
On Error GoTo endit
Application.EnableEvents = False
If Me.Range("A1") = "" Then
macroname
End If
endit:
Application.EnableEvents = True
End Sub

Right-click on the sheet tab and "View Code". Copy/paste to the sheet module.

Note: will not fire if A1 is just blank as in contents cleared.

For that you would need something like this.

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo endit
Application.EnableEvents = False
If Me.Range("A1") = "" Then
macroname
End If
endit:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP


On Tue, 14 Aug 2007 09:04:00 -0700, LW_Greeney
wrote:

mIS there anyway we can activate a macro from within a formular for exaple if
cell A1 ="" then run Macro?