I am trying to display milliseconds in an Excel macro. I have a column of integers which are simply timestamps in milliseconds (e.g. 28095200 is 7:48:15.200 am), and I want to make a new column next to it which keeps a running average and displays the time in a "hh:mm:ss.000" format. I have tried multiple different routes, but I simply can't get the milliseconds without causing weird things to happen.
Here's what I have right now:
Dim Cel As Range
Set Cel = Range("B1")
temp = Application.Average(Range("A1:A2")) / 1000
ms = Round(temp - Int(temp), 2) * 1000
Cel.Value = Strings.Format((temp / 60 / 60 / 24), "hh:mm:ss") _
& "." & Strings.Format(ms, "#000")
For some reason, this only displays "mm:ss.0" in the cell. Yet when I click on the cell, it shows "hh:mm:ss" in the formula bar. Why are the hours missing in the cell?
Also, another weird thing that happens is if I change the last line to Strings.Format(ms, "#000.")
, then I get "hh:mm:ss.000." That's what I want, just not the extra period.