ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Milliseconds in Excel (https://www.excelbanter.com/excel-programming/327298-milliseconds-excel.html)

dhg4

Milliseconds in Excel
 
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)


Fredrik Wahlgren

Milliseconds in Excel
 

"dhg4" wrote in message
ups.com...
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



Tom Ogilvy

Milliseconds in Excel
 
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

--
Regards,
Tom Ogilvy

"dhg4" wrote in message
ups.com...
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)




dhg4

Milliseconds in Excel
 
Tom,
Thanks a lot. That did the trick.
I really appreciate it!
David



All times are GMT +1. The time now is 02:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com