Running a Macro from a formula


Posted by David Merikansky on December 10, 2001 9:59 AM

Hi, I'm trying to run a macro from a formula, in which I allready wrote the macro and I can either run it by pressing a button or by pressing the assigned ctrl key. Wwhat I want to do is something like this in C1:
=If(A1=B1,"RUN MACRO",B1)
Is there any way I can do it? thanks in advance.
I would appreciate if you can write me an e-mail with your suggestions.

Posted by Dan on December 10, 2001 10:19 AM

You can't do it from a formula on a worksheet. You have to do it from VBA. Insert this in the your code under the "ThisWorkbook" project, and it should work the way you want.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Excel.Range)
If Target.Address = "$B$1" Then
If Range("B1") = Range("A1") Then InsertNameOfMacroHere
End If
End If
End Sub

Posted by David on December 10, 2001 4:06 PM

Unfurtunally, This didn't work, but I do apreciate your kindness Dan... any other sugestions???



Posted by Bariloche on December 10, 2001 5:38 PM

What about it doesn't work?

David,

What aspect of it didn't work?

Have you checked the scope of the macro that you're calling to make sure its visible to the SelectionChange event macro? What error was generated?

I haven't delved into this, but the solution that Dan posted is substantially the same as what I would have posted.


take care