VBA to test Macro Speed

Muhamed Faizal

Board Regular
Joined
Aug 18, 2011
Messages
204
Using following code, I could make speed of my Macro in Seconds.

Sub Speed()
StartTime = Timer
'
'other code goes here
'
MsgBox "This report prepared in " & Timer - StartTime & "Seconds"
End Sub

How do I convert the time in hh:mm:ss format?

Thanks in advance
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Use instead:

Code:
Format((Timer - StartTime) / 86400, "hh:mm:ss")

There are 86400 seconds in a day, which is the unit interval for Timer.
 
Last edited:
Upvote 0
I edited my message - did you test the last version?
 
Upvote 0
Yip I'd go with wigi

Code:
Format((endt - Start) / 86400, "hh:mm:ss")

returns 00:00:04 for a 4 second runtime
 
Upvote 0
I edited my message - did you test the last version?

Wonderful, It works perfectly<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
Thank You Wigi<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"> <v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shapetype><v:shape id=_x0000_i1025 style="WIDTH: 12pt; HEIGHT: 12pt" alt="0" type="#_x0000_t75"><v:imagedata o:href="http://www.mrexcel.com/forum/images/smilies/biggrin.gif" src="file:///C:\DOCUME~1\mfaizal\LOCALS~1\Temp\msohtml1\01\clip_image001.gif"></v:imagedata></v:shape><o:p></o:p>
 
Upvote 0
You could also use the Now() function
Code:
Sub test()
    Dim Start, Finish, Time As Date
    Dim i As Long

    Start = Now

    'adding some code just to delay a bit for an example
    For i = 1 To 1000000000
    Next i

    Finish = Now

    Time = Finish - Start
    MsgBox Time
End Sub
 
Last edited:
Upvote 0
Hello Jean

Thank you for contributing.

I would not use Time, since that is a reserved word. But you could use it if you wanted.

Also, note that your variables Start and Finish are declared as Variants, not as Date.
You need to repeat the "As Date" twice.
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,356
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top