Formula to activate macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings. Is there a way you can activate a macro through a formula.
Example:
=if(A1=B1,(macro here),"")? Thanks in advance.
 
Consider using a Worksheet Calculate Event macro (not Change Event) to
monitor the cell in question and call your macro when conditions are right.
 
This should get you started.

You could attach some code to the Worksheet Change that checks to see
if the two cells are equal and if so run some code. This method will
check every time something is entered. I'm sure it needs to be
modified for you needs but should give you a starting point.

Private Sub Worksheet_Change(ByVal Target As Range)
Set Target = Sheets("Sheet1").Range("A1:B1")
If Sheets("Sheet1").Range("A1") = Sheets("Sheet1").Range("B1") Then
MsgBox "(put code here)"
End If
End Sub

- John
 
Good afternoon Coal_miner

It is not possible for a cell to initiate a macro.

Once workaround would be an event procedure set up (in
Workbook_SheetChange) that monitors a cell and compares its value to
another cell and if true then a macro is called.

HTH

DominicB
 
A little more generic:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Worksheet.Range("A1") = Target.Worksheet.Range("B1") Then
MsgBox "Example"
'' or put a macro name here
End If
End Sub
 
Temp said:
A little more generic:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Worksheet.Range("A1") = Target.Worksheet.Range("B1") Then
MsgBox "Example"
'' or put a macro name here
End If
End Sub

I found this thread by using search, thanks.

So I make the above a new macro and run it first every time I start th
xls file? or
 

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

Back
Top