Can a Macro be run as part of an IF() statement

G

Guest

Can I run a macro as part of an IF statement i.e. IF(A2=1,Run Macro 1,Do
nothing ) I simplified what I want to happen but I want to automatically run
a macro when a condition goes true in another cell.
 
G

Gord Dibben

You cannot do it in a formula but event code could run the macro when A1=1

Private Sub Worksheet_Calculate()
On Error GoTo stoppit
Application.EnableEvents = False
With Me.Range("A1")
If .Value = 1 Then
'MsgBox "Please be advised that A1 is equal to 1"
Macroname
End If
End With
stoppit:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP
 

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