ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Autorun Macro (https://www.excelbanter.com/excel-programming/292643-autorun-macro.html)

RK[_3_]

Autorun Macro
 
How do I get a macro to auto run (not on starting excel, but at any time).

Say whenever the value in cell A1<5, automatically Call Macro1



Frank Kabel

Autorun Macro
 
Hi
you can use the worksheet_change event. Put the following in your
worksheet module:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit Sub
On Error GoTo CleanUp:
With Target
If .Value < 5 Then
Application.EnableEvents = False
' insert your code
End If
End With
CleanUp:
Application.EnableEvents = True
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany

RK wrote:
How do I get a macro to auto run (not on starting excel, but at any
time).

Say whenever the value in cell A1<5, automatically Call Macro1



Tom Ogilvy

Autorun Macro
 
The best answer would depend on how A1 gets to be less than 5

If it is by someone editing the cell, then use the change event. If it is
by calculation or from a DDE link, then use the Calculate event

See Chip Pearson's page on events
http://www.cpearson.com/excel/events.htm

If using the calculate event, you would also need to consider what happens
after the cell first achieves the tested condition and the macro is run once
for that event.

--
Regards,
Tom Ogilvy

"RK" wrote in message
...
How do I get a macro to auto run (not on starting excel, but at any time).

Say whenever the value in cell A1<5, automatically Call Macro1






All times are GMT +1. The time now is 10:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com