100ths of a second

T

TADropik

is it possible to calculate 100ths or even 1000ths of a second in Excel.

I can calculate the time difference between 2 cells down to the second, but
is it possible to calculate down to the 100th of a second?
 
R

RB Smissaert

Use the TimeGetTime API.

Option Explicit
Private lStartTime As Long
Private Declare Function timeGetTime Lib "winmm.dll" () As Long

Sub StartSW()
lStartTime = timeGetTime()
End Sub

Function StopSW(Optional bMsgBox As Boolean = True, _
Optional vMessage As Variant, _
Optional lMinimumTimeToShow As Long = -1) As Variant

Dim lTime As Long

lTime = timeGetTime() - lStartTime

If lTime > lMinimumTimeToShow Then
If IsMissing(vMessage) Then
StopSW = lTime
Else
StopSW = lTime & " - " & vMessage
End If
End If

If bMsgBox Then
If lTime > lMinimumTimeToShow Then
MsgBox "Done in " & lTime & " msecs", , vMessage
End If
End If

End Function


Sub test()

Dim i As Long

StartSW
For i = 1 To 10000000

Next i
StopSW

End Sub


RBS
 
T

TADropik

That worked perfect.
Thank you for that.

Now if I can just get macros to run on my Cell Phone I have a nice little
stop watch to carry with me. ;-)
 

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