Public StopIt As BooleanPublic ResetIt As Boolean
Public LastTime
Private Sub CommandButton1_Click()
Dim StartTime, FinishTime, TotalTime, PauseTime
StopIt = False
ResetIt = False
If Range("C2") = 0 Then
StartTime = Timer
PauseTime = 0
LastTime = 0
Else
StartTime = 0
PauseTime = Timer
End If
StartIt:
DoEvents
If StopIt = True Then
LastTime = TotalTime
Exit Sub
Else
FinishTime = Timer
TotalTime = FinishTime - StartTime + LastTime - PauseTime
TTime = TotalTime * 100
HM = TTime Mod 100
TTime = TTime \ 100
hh = TTime \ 3600
TTime = TTime Mod 3600
MM = TTime \ 60
SS = TTime Mod 60
Range("D2").Value = Format(hh, "00") & ":" & Format(MM, "00") & ":" & Format(SS, "00") & "." & Format(HM, "00")
If ResetIt = True Then
Range("D2") = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
LastTime = 0
PauseTime = 0
End
End If
GoTo StartIt
End If
End Sub
Private Sub CommandButton2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim j As Range
StopIt = True
Range("J2").Value = Range("J2").Value + Range("D2").Value
End Sub
Private Sub CommandButton3_Click()
Dim Lastrow As Integer
Dim LLastrow As Integer
LLastrow = ActiveSheet.Cells(Rows.Count, "L").End(xlUp).Row + 1
Lastrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
Range("L" & LLastrow).Value = Range("J2").Value
Range("D2, J2").Value = Format(0, "00") & ":" & _
Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
LastTime = 0
Range("B2:B" & Lastrow).ClearContents
ResetIt = True
End Sub
Private Sub CommandButton4_Click()
Dim Lastrow As Integer
Lastrow = ActiveSheet.Cells(Rows.Count, 12).End(xlUp).Row
Range("L2:L" & Lastrow).ClearContents
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo endit
If Target.Address = "$J$2" Then
Application.EnableEvents = False
j = Cells(Cells.Rows.Count, "B").End(xlUp).Row + 1
Cells(j, 2) = Range("D2").Value
End If
endit:
Application.EnableEvents = True
End Sub