VBA Code for displaying time taken by a macro

  • Thread starter Thread starter Macro man
  • Start date Start date
M

Macro man

hi,

can you pls give me the VBA Code for diplaying the time taken by a
macro to give the output.

Regards,

Karthik
 
One way:

Dim time1 As Double, time2 As Double
time1 = Timer
' <your macro here>
time2 = Timer
MsgBox Format(time2 - time1, "0.00 \s\ec")
 
Depends upon how accurate you want it. If you want it to get an idea of the
performance of one piece of code over another then a very simple method is
to set a timer at the start and then check against it at the end

Dim nTime

Timer = nTime

.... your code

Debug.Print Timer - nTime

run the code a number of times and average teh results.

If you need more accuracy, search for Hi-Res Timer in the excel newsgroups
in Google, http://tinyurl.com/a4dov

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Type, should be

nTime = Timer

at start

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Back
Top