View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default trouble with subtracting elapsed times

Try the following example. I put a stop in it so that you can hover the
cursor over the variables and see what they return after viewing the 2
MsgBox's.

The correct values are being returned. What occurs is that because VBA does
not handle hours from 2400 and above, the full day is subtracted and only
leaves the fractional portion but it you use the worksheetfunction.text to
display it then it is correct.

I understand your confusion. I've been through it and it took me quite
sometime to come to grips with it. That is the reason that I said to work
with the VBA variables and only use the Text function to display the value
and do not try to return the value from a userform textbox and use it in
calculations.

Sub test()

Dim time1 As Date

Dim start As Date

'Date and time in Range("B6")
'is 06 Aug 2009 09:35:24 PM

start = Sheets("Timing Sheet").Range("B6")

time1 = Now() - start

MsgBox WorksheetFunction.Text(time1, "[hh]:mm:ss")

MsgBox WorksheetFunction.Text(time1, "00.000000")

Stop

End Sub


--
Regards,

OssieMac