Hey guys,
First of all, cool stopwatch. I've thought about something like this for awhile, but never thought of an easy way to do it. Your code is great. I did, however make a few modifications. (basically formatting)
1. I formatted the time so that it displays as h:mm:ss.00, I did this
for the sheet and in the code.
e.g. 1:03:04.56 instead of 1:3:4.5643
2. I added a "Lap" column in C
(the difference between adjacent times)
e.g. If A2 = 0:01:12.56 and A3 = 2:12.56
C3 = 0:01:00.00
This fomatting allows me to manipulate the number later. For example I can use the Average function to Average splits. I can sort the times or filter out all times between a certain criteria.
I don't see any easy way to make the sheet respond faster (that is record more than 2 times in 1 sec.) If I was to use this in practice, say at a road race, I would have the traditional hand timer as back up, and fill in the missing times on the spreadsheet after the race.
I tried to highlight my changes below, but I may have missed a few.
(I also had to take out the " " in one or two places.)
Hope this is a useful modification for someone.
~ Dan
Public StopSW As Boolean
Public ReSetSW As Boolean
Public SplitSW As Boolean
Public myTime
Sub stopwatch()
'Seconds and fractions of seconds Timer!
'Sheet Module code!
Dim Start, Finish, TotalTime
Dim myHi!, myH%, myMi!, myM%, mySi!, myS%, mySf!, SubTotalT
Dim newtime
'Format Time cell.
Sheets("Sheet1").Range("B1").Select
With Selection
.Font.Bold = True
.Font.Name = "Arial"
.Font.Size = 12
.Font.ColorIndex = xlAutomatic
End With
Sheets("Sheet1").Range("A1").Select
With Selection
.Interior.ColorIndex = 36
.Borders(xlEdgeLeft).Weight = xlThick
.Borders(xlEdgeLeft).ColorIndex = 49
.Borders(xlEdgeTop).Weight = xlThick
.Borders(xlEdgeTop).ColorIndex = 49
.Borders(xlEdgeBottom).Weight = xlThick
.Borders(xlEdgeBottom).ColorIndex = 49
.Borders(xlEdgeRight).Weight = xlThick
.Borders(xlEdgeRight).ColorIndex = 49
.Font.Name = "Arial"
.Font.Size = 14
.Font.ColorIndex = xlAutomatic
.Font.Bold = True
End With
'Set timer.
Start = Timer
StopSW = False
ReSetSW = False
myTime = Sheets("Sheet1").Range("AA1").Value
Sheets("Sheet1").Range("A1").Select
myStart:
'Yield to other processes.
DoEvents
'Calculate time.
Finish = Timer
TotalTime = Finish - Start
SubTotalT = myTime + TotalTime
myHi = Application.WorksheetFunction.RoundDown(SubTotalT / 3600, 0)
myH = myHi
myMi = Application.WorksheetFunction.RoundDown(((SubTotalT - (myH * 3600)) / 60), 0)
myM = myMi
mySi = Application.WorksheetFunction.RoundDown(SubTotalT - ((myH * 3600) + (myM * 60)), 0)
myS = mySi
mySf = SubTotalT - ((myH * 3600) + (myM * 60) + myS)
newtime = Format(Format(myH, "0") & ":" & Format(myM, "00") & ":" & _
Format(myS, "00") & Format(mySf, ".00"), "h:mm:ss.00") ' & " H:M:S"[/b]
'Show time on sheet!
'Sheets("Sheet1").Range("A1").Value = Format(myTime + TotalTime, "0.0000") & " Seconds"
Sheets("Sheet1").Range("AB1").Value = Format(TotalTime, "h:mm:ss.00")
Sheets("Sheet1").Range("A1").Value = Format(newtime, "h:mm:ss.00")
'Test for "ReSet!"
If ReSetSW = True Then
Sheets("Sheet1").Range("B1").Value = " <== Total Time"
Sheets("Sheet1").Range("A1").Value = Format(" 0:00:00.0", "h:mm:ss.00")
Sheets("Sheet1").Range("AA1").Value = Format(0, "h:mm:ss.00")
StopSW = True
'Test for "Stop!"
End If
If Not StopSW = True And SplitSW = False Then
Sheets("Sheet1").Range("AA1").Value = TotalTime
GoTo myStart
End If
'Test for "Split!"
If SplitSW = True Then
'Sheets("Sheet1").Range("A65536").End(xlUp).Offset(1, 0).Value = Format(TotalTime, "0.0000")
Sheets("Sheet1").Range("A65536").End(xlUp).Offset(1, 0).Select
With Selection
.Value = newtime
.Interior.ColorIndex = 35
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlThin
.Borders(xlEdgeLeft).ColorIndex = 51
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlEdgeBottom).ColorIndex = 51
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).Weight = xlThin
.Borders(xlEdgeRight).ColorIndex = 51
End With
Selection.Offset(0, 1).Value = " <== Split # : " & Selection.Offset(0, 1).Row - 1
Selection.Offset(0, 2).Value = Selection.Offset(0, 0).Value - Selection.Offset(-1, 0).Value
Sheets("Sheet1").Range("AA1").Value = TotalTime
Sheets("Sheet1").Range("A1").Select
SplitSW = False
GoTo myStart
End If
End
End Sub
Sub myQuit()
StopSW = True
End Sub
Sub myReSet()
Sheets("Sheet1").Range("A1").Value = 0
Sheets("Sheet1").Range("AA1").Value = 0
Range("A2:C65536").Select
With Selection
.ClearContents
.Interior.ColorIndex = xlNone
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
End With
Sheets("Sheet1").Range("B1").Value = " <== Total Time"
Sheets("Sheet1").Range("A1").Select
Selection.Value = Format(" 0:00:00.0", "h:mm:ss.00")ReSetSW = True
SplitSW = False
End Sub
Sub mySplit()
DoEvents
SplitSW = True
End Sub