Run a macro when cell value changes

E

Emea training

I have a macro that I would like to run, onlly when a particular cel
value reaches a pre-defined value.

I really do not know how to do this - I have looked on help features
but to no avail. any ideas
 
D

Don Guillett

right click sheet tab>view code>copy/paste this>modify to suit>save
Now when cell c1 calculates to >32 your macro will fire

Private Sub Worksheet_Calculate()
If Range("c1") > 32 Then call yourmacro ' MsgBox "Hi"
End Sub
 
N

nowfal

Great answer,
I have a little bit near question, is it possibl
to do it without having any number, if i enter into a particular blan
cell say 'J2', to activate the macro or run the macro.
thank u.
nowfa
 
G

Gord Dibben

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo enditall
Application.EnableEvents = False
If Target.Address = "$B$3" Then
If Target.Value > 100 Then
Call macroname
End If
End If
enditall:
Application.EnableEvents = True
End Sub

Right-click on your worksheet tab and "View Code"

Copy/paste the above code into that sheet module.

Your cell reference and value may vary. Adjust to suit. Also change
"macroname" to your macro name.

Gord Dibben Excel MVP
 
D

Dave Peterson

Does "enter into a particular blank cell" mean you typed something into it or
just selected it?
 
N

nowfal

I just wanted to select it, neither number nor text in that cell, an
new ideas.
thank
 
A

Andy Wiggins

In the worksheet's module:

Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox "Changed"
End Sub

It can be confusing to see only part of a thread. This is a draw back of
using a web-based forum.
You might find it better to use the source newsgroup
(microsoft.public.excel.misc).

--
Regards
Andy Wiggins
www.BygSoftware.com
Home of "Save and BackUp",
"The Excel Auditor" and "Byg Tools for VBA"
 
Top