PDA

View Full Version : Running Stopwatch Assigned to Buttons



kimbap
11-18-2012, 08:21 AM
Hi,


Good Day.

Could anyone please help me with my current project?


The post made by Zack Barresse (Topic: Create a StopWatch in Excel) is almost exactly with my project (Kudos to Zack). The only difference is, instead of double-clicking, the macro is assigned to a button. There are 3 buttons to be precise. One is the Start Button (hitting this button will start the stopwatch). Second is the Pause Button (hitting this button will will pause the stopwatch). And lastly is the Resume Button (hitting this button will resume the stopwatch).


Thank you very much. This site rocks. More power.



Post made by Zack Barresse:

Public stopMe As Boolean
Public resetMe As Boolean
Public myVal As Variant
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 1 Then
If Target.Value = myVal And Target.Value <> "" Then
'Changed
Dim startTime, finishTime, totalTime, timeRow
startTime = Timer
stopMe = False
resetMe = False
myTime = Target.Offset(, 2).Value
Target.Offset(, 1).Select
startMe:
DoEvents
timeRow = Target.Row
finishTime = Timer
totalTime = finishTime - startTime
Target.Offset(, 1).Value = Format(myTime + totalTime, "0.0000") & " Seconds"
If resetMe = True Then
Target.Offset(, 1).Value = 0
Target.Offset(, 2).Value = 0
stopMe = True
End If
If Not stopMe = True Then
Target.Offset(, 2).Value = totalTime
Goto startMe
End If
Cancel = True
End
Else
'Not Changed
stopMe = True
Cancel = True
End If
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
myVal = Target.Value
End Sub

GarysStudent
11-18-2012, 09:14 AM
So what do you want changed??

kimbap
11-18-2012, 10:07 AM
Thanks for taking interest Gary...

I want to replace doubleclicking to a Macro Button instead... 3 Macro buttons to be precise. One is the Start Button (hitting this button will start the stopwatch). Second is the Pause Button (hitting this button will will pause the stopwatch). And lastly is the Resume Button (hitting this button will resume the stopwatch).

kimbap
11-18-2012, 05:20 PM
Ohhhh... I forgot to mention how to use the above code...

Here it goes:

Enter a value in column A.

Double click said value to start StopWatch.
Double click said value while StopWatch is running to reset at specified (col C) interval.
Double click a blank cell to stop SopWatch.
*** Also, I will not be using reset in my project. I would also like to replace the Reset Code to Resume Code instead.


Many Thanks