GaryRussell wrote:I must have done that some time ago because I would write that slightly differently now. Try the following.
- Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count = 16 Then
Application.EnableEvents = False
If Cells(2, 5) = "In Play" Then
If Cells(1, 27) = "" Then Cells(1, 27) = Cells(2, 3)
If Cells(1, 27) <> "" Then Cells(1, 28 ) = DateDiff("s", Cells(1, 27), Cells(2, 3))
End If
If Cells(2, 5) <> "In Play" And Cells(2, 6) <> "Suspended" Then
Cells(1, 27) = ""
Cells(1, 28 ) = ""
End If
Application.EnableEvents = True
End If
End Sub
lindemann wrote:
Excel,
Have a look at this thread:
http://www.gruss-software.co.uk/forum/v ... php?t=7455
Thanks for that Gary - now not freezing ! . Strange that my amended version works fine on the horses though.
Thanks also go out to lindemann I am using his/your code with my minor change in the following markets:
Half Time Score - Sheet 1
Half Time / Full time - Sheet 2
I am hoping I can use those markets to tell when HT starts and second half begins. Should know in about 2 hours. Here is the code:
Sheet1:
Dim timeInPlay As Date
Dim turnedInPlay As Boolean
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count = 16 Then
If Range("F2").Value = "Closed" Then
If Not turnedInPlay Then
turnedInPlay = True
timeInPlay = Now
End If
Else
turnedInPlay = False
End If
If turnedInPlay Then Range("T1").Value = DateDiff("s", timeInPlay, Now) Else Range("T1").Value = 0
End If
End Sub
Sheet2:
Dim timeInPlay As Date
Dim turnedInPlay As Boolean
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count = 16 Then
If Range("E2").Value = "InPlay" And Range("U1") = "Closed" Then
If Not turnedInPlay Then
turnedInPlay = True
timeInPlay = Now
End If
Else
turnedInPlay = False
End If
If turnedInPlay Then Range("T1").Value = DateDiff("s", timeInPlay, Now) Else Range("T1").Value = -1
End If
End Sub