Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default change event

You'll need to use the Worksheet_Calculate event instead.

To detect a change in value, you'll need to save the value in a module
or static variable so you can compare the old value to the current value.

For instance:

In a regular code module:

Public vOldC38Value As Variant

In the ThisWorkbook module:

vOldC38Value = Sheets("Sheet1").Range("C38").Value

In the worksheet code module:

Private Sub Worksheet_Calculate()
With Range("C38")
If .Value < vOldC38Value Then
vOldC38Value = .Value
Macro2
End If
End With
End Sub


In article ,
enyaw wrote:

I have the following code that runs a macro when the cell value chages.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$38" Then
Call Macro2
End If
End Sub

The problem I have that cell C38 contains a formula and will not run the
macro because any change in value is not picked up. Can anyone help me?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default change event

Try following JE's suggestion once more.

And if you still have trouble, you may want to give a little more info.

enyaw wrote:

The debugger tells me that there is a compile error.
Range C38 is invalid outside procedure. in the ThisWorkbook module.
I would also like it to work for the range c38:c51.

"JE McGimpsey" wrote:

You'll need to use the Worksheet_Calculate event instead.

To detect a change in value, you'll need to save the value in a module
or static variable so you can compare the old value to the current value.

For instance:

In a regular code module:

Public vOldC38Value As Variant

In the ThisWorkbook module:

vOldC38Value = Sheets("Sheet1").Range("C38").Value

In the worksheet code module:

Private Sub Worksheet_Calculate()
With Range("C38")
If .Value < vOldC38Value Then
vOldC38Value = .Value
Macro2
End If
End With
End Sub


In article ,
enyaw wrote:

I have the following code that runs a macro when the cell value chages.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$38" Then
Call Macro2
End If
End Sub

The problem I have that cell C38 contains a formula and will not run the
macro because any change in value is not picked up. Can anyone help me?



--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default change event

Try:

First, name your range, say, "CheckRange"

Then a regular code module:

Public vOldValues As Variant

In the ThisWorkbook code module:

Private Sub Workbook_Open()
vOldValues = ThisWorkbook.Names("CheckRange").RefersToRange.Val ue
End Sub

In the worksheet code module that contains CheckRange:

Private Sub Worksheet_Calculate()
Dim i As Long
With Range("CheckRange")
For i = 1 to .Cells.Count
If .Cells(i).Value < vOldValues(i, 1) Then
vOldValues(i, 1) = .Cells(i).Value
Macro2
End If
Next i
End With
End Sub

Or, if you only want Macro2 to run once, no matter how many cells have
changed:


Private Sub Worksheet_Calculate()
Dim i As Long
With Range("CheckRange")
For i = 1 to .Cells.Count
If .Cells(i).Value < vOldValues(i, 1) Then
vOldValues = .Value
Macro2
End If
Next i
End With
End Sub


In article ,
enyaw wrote:

I would also like it to work for the range c38:c51.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 469
Default change event

Think this is what I am looking for. Problem is I have entries that copy to
another worksheet. Want if any entry in row is changed need code to go to
copied entry and make change there also. Useing event to copy data. This
valadation on change is problem. Working primilary with text in cells. trying
to have multiple ifs in event code
Thanks
old dog new tricks

"JE McGimpsey" wrote:

You'll need to use the Worksheet_Calculate event instead.

To detect a change in value, you'll need to save the value in a module
or static variable so you can compare the old value to the current value.

For instance:

In a regular code module:

Public vOldC38Value As Variant

In the ThisWorkbook module:

vOldC38Value = Sheets("Sheet1").Range("C38").Value

In the worksheet code module:

Private Sub Worksheet_Calculate()
With Range("C38")
If .Value < vOldC38Value Then
vOldC38Value = .Value
Macro2
End If
End With
End Sub


In article ,
enyaw wrote:

I have the following code that runs a macro when the cell value chages.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$38" Then
Call Macro2
End If
End Sub

The problem I have that cell C38 contains a formula and will not run the
macro because any change in value is not picked up. Can anyone help me?


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
MsgBox in Enter event causes combobox not to run Change event Richard Excel Programming 0 March 6th 06 02:52 PM
Change event and calculate event Antje Excel Programming 1 March 29th 05 09:03 PM
Change Cell from Validated List Not Firing Worksheet Change Event [email protected] Excel Programming 3 October 4th 04 03:00 AM
change event/after update event?? scrabtree23[_2_] Excel Programming 1 October 20th 03 07:09 PM


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