formula to run macro

albion

New member
Joined
Jun 18, 2014
Messages
1
Reaction score
0
Points
0
Hi. Just new to this site. It looks very informative. I have a question. Is it possible to have an IF formula qualify certain criteria and then command a macro?
 
Yes.
Try this:
in cell F13 your IF formula, say:
=IF(E13=D13,TRUE,"")

Right-click that sheet's tab and paste these two macros:
Code:
Private Sub Worksheet_Calculate()
If Range("F13") = True Then blah
End Sub

Sub blah()
MsgBox "Hello!"
End Sub

Now change E13 and D13 on the sheet to the same.

You could do this another way, a bit shorter by eliminating the IF formula in cell F13 and deleting the Sheet_Calculate event handler (macro), replacing it with the sheet_change event handler:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("D13") = Range("E13") Then blah
End Sub
 
Back
Top