I can't see that Mike's code doesn't do exactly as requested but here is another post on the forum where the code could be adapted (see sheet in post #1).
http://www.excelforum.com/excel-prog...bike-laps.html
If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved
Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown
Thanks.
I'm going to try out all your suggestions today. I'll post back after.
-D
Hi mikerickson
You code is working really well. The only thing I'd like to alter is the cells in which the times get listed A1-C1 and A2-C2 and so on.
Instead of the the stop watch moving through the range of A-C. I'd like the stop watch to start in B23 and then list through B23, C23, D23 and then B24, C24, D24 and so on.
I tried playing around with the offsets and LastCellInA... but I didn't achieve anything other than moving around the interior color. Am going to keep playing with it.
Any suggestions?
Thank you.
This should work. If you change your mind about B23, just change the indicated line in Function LastCellInColumn.
![]()
Function LastCellInColumn(Optional ReturnBase As Boolean) Dim startCell As Range With ThisWorkbook.Sheets("Sheet1") Set startCell = .Range("B23"): Rem adjust <<<<<<<<<<<<<<<<<<<<< Set LastCellInColumn = .Cells(.Rows.Count, startCell.Column).End(xlUp) End With If ReturnBase Or (LastCellInColumn.Row < startCell.Row) Then Set LastCellInColumn = startCell End Function Sub StartButton() Rem set named value StartTime to Now ThisWorkbook.Names.Add Name:="StartTime", RefersTo:="=" & CDbl(Now()) Rem mark that timer is on LastCellInColumn.Interior.Color = vbYellow End Sub Sub StopButton() Dim StartTime As Date On Error Resume Next StartTime = CDate(Evaluate(Names("StartTime").RefersTo)) On Error GoTo 0 If 0 < StartTime Then Rem if timer is running With LastCellInColumn .Interior.ColorIndex = xlNone Rem write interval With .Offset(0, 2) .Value = Now() - StartTime .NumberFormat = "h:mm:ss" End With Rem calculate adjusted start time With .Offset(0, 1) .Value = .Offset(0, 1).Value + .Offset(0, -1).Value .NumberFormat = "h:mm:ss" End With Rem prepare next row With .Offset(1, 0) .Value = .Offset(-1, 1).Value .NumberFormat = "h:mm:ss" End With End With Rem turn off timer by setting name StartTime to 0 ThisWorkbook.Names.Add Name:="StartTime", RefersTo:="=0" End If End Sub Sub MarkButton() If ThisWorkbook.Names("StartTime").RefersTo <> "=0" Then Call StopButton Call StartButton End If End Sub Sub ClearButton() Dim strPrompt As String If ThisWorkbook.Names("StartTime").RefersTo <> "=0" Then strPrompt = "The timer is running" & vbCr & vbCr End If strPrompt = strPrompt & "Clear data?" & vbCr & "There is no un-do." If MsgBox(strPrompt, vbYesNo) = vbYes Then Call StopButton Range(LastCellInColumn, LastCellInColumn(True)).Resize(, 3).ClearContents With LastCellInColumn .Resize(1, 3).Value = Split("Start Time,End Time,Duration", ",") .Offset(1, 0).Value = 0 .Offset(1, 0).NumberFormat = "h:mm:ss" End With End If End Sub
Last edited by mikerickson; 06-16-2012 at 05:51 PM.
_
...How to Cross-post politely...
..Wrap code by selecting the code and clicking the # or read this. Thank you.
mikerickson... I don't know who you are- but you're a hero in my book!
Thanks a lot for the code. It works perfectly.
-D
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks