View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Cell Change triggers Worksheet Event

Then you left the "dot" in there by mistake.<g As for whether the
Precedents property call is needed or not... it might be. What if, in the
most simplest form, you had this in A1...

=B1<""

and in B1 you had this...

=C1<""

If C1 changes, then A1 will change, but the Change event code will not be
triggered if all you check is A1 in the event... you would need to check
A1's Precedents to get the right trigger for the event. Since the OP said
his code for the single cell (which contained a formula) that he checked
the Precedents for worked, I assumed the Precedents property call would be
needed in the modified code as well.

--
Rick (MVP - Excel)


"Bob Phillips" wrote in message
...
I deliberately dropped the Precedents, couldn't see the point of it.

HTH

Bob

"Rick Rothstein" wrote in message
...
If Not Intersect(Target, Range("S2:S75").) Is Nothing Then


You have the "dot" after the range, but you forgot the Precedents keyword
after it...

If Not Intersect(Target, Range("S2:S75").Precedents) Is Nothing Then

--
Rick (MVP - Excel)


"Bob Phillips" wrote in message
...
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
On Error GoTo errExit
Application.EnableEvents = False
If Not Intersect(Target, Range("S2:S75").) Is Nothing Then

If Target.Value < 0 Then
' do something
MsgBoxTarget.Value
End If
End If

errExit:
Application.EnableEvents = True
End Sub

"Charles" wrote in message
...
HI,

I'm trying to trigger a worksheet event thru a cell or cells value
being changed.
I found this code in this forum and it does what I'm trying to do,
however, I'm trying to have the event activated when a cell value
change within a column. The range I'm looking at is Range("S2:S75").
The values in this range are derived by a formula. Here's the code

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
On Error GoTo errExit
Application.EnableEvents = False
Set rng = Range("s7").Precedents

If Not Intersect(Target, rng) Is Nothing Then

If Range("s7").Value < 0 Then
' do something
MsgBox Range("s7").Value
End If
End If

errExit:
Application.EnableEvents = True
End Sub

This code works, but it only looks at 1 cell, and I need it to look at
the range specified.

Any help or suggestion would be appreciated.