Thread: Runtime Error
View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Runtime Error

Hi Carlton,

I truncated the Sub header line in my post.

The code, which works for me, responds (only) if an entry 7 is made in
one, or more of the A1:A5 cells.

With the header, the code should read:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Integer
Dim NextTime As Date
Dim Rng1 As Range, Rng2 As Range, rCell As Range

If Intersect(Target, Me.Range("A1:A5")) Is Nothing _
Then Exit Sub

Set Rng1 = Intersect(Target, Me.Range("A1:A5"))

If Application.Max(Rng1) <= 7 Then Exit Sub

For Each rCell In Rng1.Cells
If rCell.Value 7 Then
If Not Rng2 Is Nothing Then
Set Rng2 = Union(Rng2, rCell)
Else
Set Rng2 = rCell
End If
End If
Next

With Rng2
For n = 1 To 5
With .Font
If .ColorIndex = 2 Then .ColorIndex = 3 _
Else .ColorIndex = 2
End With
With .Interior
If .ColorIndex = 3 Then .ColorIndex = 2 _
Else .ColorIndex = 3
End With
Application.Wait Now + TimeValue("00:00:01")
Next

.Font.ColorIndex = 3
.Interior.ColorIndex = 2

End With

End Sub


---
Regards,
Norman



"Carlton Patterson" wrote in message
...
Hi Norman,

Thanks for your efforts mate. However, when I insert a number in any of
the fields between A1:A5 nothing happens.

Carlton



*** Sent via Developersdex http://www.developersdex.com ***