Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
coal_miner
 
Posts: n/a
Default Formula to activate macro

Greetings. Is there a way you can activate a macro through a formula.
Example:
=if(A1=B1,(macro here),"")? Thanks in advance.
  #2   Report Post  
Gary's Student
 
Posts: n/a
Default

Consider using a Worksheet Calculate Event macro (not Change Event) to
monitor the cell in question and call your macro when conditions are right.
--
Gary's Student


"coal_miner" wrote:

Greetings. Is there a way you can activate a macro through a formula.
Example:
=if(A1=B1,(macro here),"")? Thanks in advance.

  #3   Report Post  
John Michl
 
Posts: n/a
Default

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

  #4   Report Post  
dominicb
 
Posts: n/a
Default


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


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=396822

  #5   Report Post  
Temp
 
Posts: n/a
Default

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



  #6   Report Post  
MikeZ
 
Posts: n/a
Default


Temp Wrote:
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 the
xls file? or?


--
MikeZ
------------------------------------------------------------------------
MikeZ's Profile: http://www.excelforum.com/member.php...o&userid=27383
View this thread: http://www.excelforum.com/showthread...hreadid=447059

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro with F9 Kenny Excel Discussion (Misc queries) 1 August 3rd 05 02:41 PM
Formula checking multiple worksheets sonic-the-mouse Excel Worksheet Functions 2 June 5th 05 07:48 PM
Insert macro into formula Paul Excel Worksheet Functions 1 May 12th 05 08:25 PM
Problem with VBA returning the contents of a long formula. [email protected] Excel Discussion (Misc queries) 2 February 23rd 05 12:14 AM
Fill Formula - Macro Cathy U Excel Discussion (Misc queries) 2 February 22nd 05 04:48 PM


All times are GMT +1. The time now is 07:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"