Milliseconds in Excel

D

dhg4

Can Excel handle milliseconds? Or is the only way to do it as a string?
The code below chokes on cDate(full_time)

full_time = Format(hr, "00") & ":" & Format(mn, "00") & ":" &
Format(sc, "00")
full_time = full_time & "." & Format(ml, "000")
Worksheets(2).Cells(ind, 1) = cDate(full_time)
 
F

Fredrik Wahlgren

dhg4 said:
Can Excel handle milliseconds? Or is the only way to do it as a string?
The code below chokes on cDate(full_time)

full_time = Format(hr, "00") & ":" & Format(mn, "00") & ":" &
Format(sc, "00")
full_time = full_time & "." & Format(ml, "000")
Worksheets(2).Cells(ind, 1) = cDate(full_time)

You can use the GetTickCount function from the Windows API. You have to
declare it as:

Option Explicit
Declare Function GetTickCount Lib "kernel32" () As Long

/Fredrik
 
T

Tom Ogilvy

I don't think it will work the way you are doing it, but this worked:

Sub BB()
Dim dt As Double
hr = 10
Min = 10
sec = 10
ml = 0.001
dt = hr / 24 + Min / (24 * 60) _
+ (sec + ml) / (24# * 60# * 60#)
ActiveCell.Value = dt
ActiveCell.NumberFormat = "hh:mm:ss.000"
Debug.Print ActiveCell.Text
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top