If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Execute Macros From Formulas (Or Cell Value)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-25-10, 19:28
indi visual indi visual is offline
Registered User
 
Join Date: Oct 2010
Posts: 3
Execute Macros From Formulas (Or Cell Value)

I would like to execute macros if specific cells change.

I have 25 cells I would like to apply this to.

After hours upon hours of failure, I would really just like to know if this even possible.

If "Z1" equals "1", then run macro
If value is not "1" do nothing
If "Z2" equals "2", then run macro
If value is not "2" do nothing
Reply With Quote
  #2 (permalink)  
Old 10-26-10, 04:40
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
You need to use event handlers to do this.
  • If the cells contain formulas then you need to use the Worksheet_Calculate() event handler.
  • If the cells contain constants then you need to use the Worksheet_Change() event handler.
The Event Handler will run everytime the respective event is raised but you can build conditional logic within the procedure so that it effectively "does nothing".
__________________
Colin

RAD Excel Blog

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote
  #3 (permalink)  
Old 03-03-11, 14:22
Nielsje Nielsje is offline
Registered User
 
Join Date: Mar 2011
Location: Amsterdam, NL
Posts: 5
Open the Visual Basic Editor and add the following code lines to the specific sheet:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$A$1" And Range("A1").Value = 1 Then MsgBox "I'm a macro"

If Target.Address = "$A$2" And Range("A2").Value = 2 Then MsgBox "I'm another macro"

End Sub
Result:

Only if the value of cell A1 changes to 1, Excel displays a Msgbox.
Only if the value of cell A2 changes to 2, Excel displays another Msgbox.

I guess this is what you want.

Hope this helps..
Reply With Quote
Reply

Tags
macro from formula

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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