#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Auto-Run

I want Excel to run the macro "Update" automatically whenever the value in
the cell named "Target" < 0. Can Excel do this without me having to run the
macro manually?

Thanks!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Auto-Run


Yes it is possible

One way

On the module sheet that is for the speadsheet you want to trigger the
macro you need a change event macro

Private Sub Worksheet_Change(ByVal Target As Range)
'add target.address testing if required
If Target.Value < 0 Then
Application.EnableEvents = False
Call MyMacro
Application.EnableEvents = True
End If
End Sub


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=522046

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Auto-Run

Hi AP,

Assuming that your intention is that the macro should only be triggered when
the cell of interest changes from zero to another value, try:

'=============
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim currCell As Range, currRng As Range
Dim oldVal As Variant
Dim newVal As Variant

Set currCell = ActiveCell
Set currRng = Selection

Set rng = Intersect(Range("myTarget"), Target)

If Not rng Is Nothing Then
On Error GoTo XIT
Application.EnableEvents = False
newVal = rng.Value
Application.Undo
oldVal = rng.Value
Target.Value = newVal
Target.Select
currCell.Activate

If oldVal = 0 And newVal < 0 Then
Call Update
End If

End If

XIT:
Application.EnableEvents = True
End Sub
'<<=============

This is worksheet event code and should be pasted into the worksheets's code
module (not a standard module and not the workbook's ThisWorkbook module):

Right-click the worksheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.

As Target is a reserved word, and to avoid possible confusion, I have
changed the named cell to myTarget


---
Regards,
Norman



"AP" wrote in message
...
I want Excel to run the macro "Update" automatically whenever the value in
the cell named "Target" < 0. Can Excel do this without me having to run
the macro manually?

Thanks!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Auto-Run

Tq norman


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Auto-Run

Hi AP,

The suggested code can be simplied.

Change:

Dim currCell As Range, currRng As Range


to

Dim currCell As Range

and delete:

Set currRng = Selection

---
Regards,
Norman



"AP" wrote in message
...
Tq norman



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
Auto-populate, Auto-copy or Auto-fill? Jay S. Excel Worksheet Functions 4 August 10th 07 09:04 PM
Sometimes formuli in workbook don't auto update with auto-recal on PE2 Excel Worksheet Functions 1 October 12th 06 03:49 PM
How to AUTO SAVE as opposed to turning on auto recovery: EXCEL T-mo Excel Discussion (Misc queries) 1 January 12th 06 10:16 PM
Auto Excel workbook close: save= false during an auto subroutine tomwashere2 Excel Programming 10 June 16th 05 06:23 AM
excel links update not working in auto, calculations in auto Mikey Boy Excel Worksheet Functions 0 December 7th 04 11:53 PM


All times are GMT +1. The time now is 07:56 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"