View Full Version : Calculating Duration
Dowsey1977
06-16-2006, 06:57 AM
Hi,
I am using the below code to try and work out the duration between 2 times automatically, but I just keep getting 0 as the duration
Start = Now
Finish = Now
Duration = Finish - Start
Any ideas why this might be?? I'm thinking possibly becuase of the formatting, but not sure...and if this is the case, not sure how to fix
Thanks in advance for any help.
johnske
06-16-2006, 07:21 AM
Sub TimeIt()
Dim Start As Double, Finish As Double
Start = Timer
'--------------------------------------
'Your code to be timed here
'--------------------------------------
Finish = Timer
MsgBox " run time was " & Finish - Start
End Sub
Dowsey1977
06-16-2006, 07:33 AM
Many thanks!
And how do I format this?? I tried changing the format to h:mm:ss and expected the result 0:00:03 on a test that I did, but 7:35:37 was displayed.
This is my full code:
Private Sub CommandButton1_Click()
If CommandButton1.Caption = "Start" Then
Start = Timer
CommandButton1.Caption = "Finish"
Range("A65000").End(xlUp).Offset(1, 0).Value = Now
Else
Range("A65000").End(xlUp).Offset(0, 1).Value = Now
Finish = Timer
Range("A65000").End(xlUp).Offset(0, 2).Value = Finish - Start
Answer = InputBox("Please enter a general description of the " & _
"task you have just completed", "Task Information")
Range("A65000").End(xlUp).Offset(0, 3).Value = Answer
CommandButton1.Caption = "Start"
End If
End Sub
mdmackillop
06-16-2006, 08:29 AM
Hi Dowsey.
Your start time is not being "remembered" by the code. Try setting A1 to Timer at Start and Timer - A1 at Finish
Regards
MD
Cyberdude
06-16-2006, 11:56 AM
Since you want a time difference, you might have to format it using the square brackets: [hh]:mm:ss
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.