Results 1 to 2 of 2

Thread: formula to run macro

  1. #1

    formula to run macro



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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?

  2. #2
    Super Moderator p45cal's Avatar
    Join Date
    Dec 2012
    Posts
    1,479
    Articles
    0
    Excel Version
    365
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •