Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 270
Default If, then: to run macro

Hi

Is it possible to have a macro run when a certain condition is met on a
worksheet (or between worksheets).

Example:

If CellA1 on sheet1 < CellA1 on sheet4 then run the macro "Evaluate"
otherwise do nothing

Thanks

Sandy


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default If, then: to run macro

Using event code


Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If .Value < "Worksheets("Shete4").Range("A1").Value Then
' do your stuff
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Sandy" wrote in message
...
Hi

Is it possible to have a macro run when a certain condition is met on a
worksheet (or between worksheets).

Example:

If CellA1 on sheet1 < CellA1 on sheet4 then run the macro "Evaluate"
otherwise do nothing

Thanks

Sandy



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default If, then: to run macro

It is possible to do this if the contents on the cells are defined by data
entry rather than calculation. The macro is called an Event Macro. For
information see:

http://www.cpearson.com/excel/excelM.htm#RunFromCell

You can use the calculate event if the cells are defined by calculations,
but you need to be careful to avoid infinite loops.
--
Gary''s Student - gsnu200716


"Sandy" wrote:

Hi

Is it possible to have a macro run when a certain condition is met on a
worksheet (or between worksheets).

Example:

If CellA1 on sheet1 < CellA1 on sheet4 then run the macro "Evaluate"
otherwise do nothing

Thanks

Sandy



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 270
Default If, then: to run macro

Thank you both - works fine

Sandy

"Sandy" wrote in message
...
Hi

Is it possible to have a macro run when a certain condition is met on a
worksheet (or between worksheets).

Example:

If CellA1 on sheet1 < CellA1 on sheet4 then run the macro "Evaluate"
otherwise do nothing

Thanks

Sandy



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
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 1 February 5th 07 09:31 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 3 February 5th 07 08:22 PM
using a cell value to control a counter inside a macro and displaying macro value ocset Excel Worksheet Functions 1 September 10th 06 05:32 AM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 1 June 11th 05 12:44 AM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 0 June 10th 05 03:38 PM


All times are GMT +1. The time now is 08:21 AM.

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

About Us

"It's about Microsoft Excel"