How to clock a procedure

  • Thread starter Thread starter 42N83W
  • Start date Start date
4

42N83W

What methods are available with VBA fro clocking procedures? I have a
subroutine that could run anywhere from 30 seconds to over 5 minutes. I'd
like to be able to display the total elapsed time for the procedure to run
in a message box (for my own edification of course, no real "need" for the
information).

Thanks!

-gk-
 
Try something like the following code:

Dim StartTime As Double
Dim EndTime As Double
StartTime = Now
'
' your code here
'
EndTime = Now
MsgBox "Procedure took: " & Format(EndTime - StartTime,
"hh:mm:ss")


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
For a simple solution, take a look at the Timer function in help.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
42N83W said:
What methods are available with VBA fro clocking procedures? I have a
subroutine that could run anywhere from 30 seconds to over 5 minutes. I'd
like to be able to display the total elapsed time for the procedure to run
in a message box (for my own edification of course, no real "need" for the
information).

Thanks!

-gk-

--
=================================================
The creative act is not the province of remote oracles or rarefied geniuses
but a transparent process that is open to everyone.
-Greg Kot in Wilco Learning How To Die-

If you need higher resolution, here's an interesting article:
http://www.dicks-blog.com/archives/2004/06/28/timing-macros/

Best Regards,
Fredrik
 
Sometimes I sprinkle lines like this to my longer running procedures:

application.statusbar = "Sorting Data Now: " & now

Then I can see the "current" step by just looking at the status bar.

And right before the code finishes, I clean up the statusbar:

application.statusbar = false
 
Hi,

I Use this One in a Couple of Programs :-

Dim Start As Double
Start = Timer

'
' Code Here
'

ActiveCell.Offset(3, 0) = "This Program Took " & _
Format(((Timer - Start) / 24 / 60 / 60), "hh:mm:ss") & " To
Process"

Application.ScreenUpdating = True
End Sub

Is this an Acceptable Way of doing this or is Chips Solution Better
Structured.

Thanks in Advance.
All the Best.
Paul



From: Chip Pearson

Try something like the following code:

Dim StartTime As Double
Dim EndTime As Double
StartTime = Now
'
' your code here
'
EndTime = Now
MsgBox "Procedure took: " & Format(EndTime - StartTime,
"hh:mm:ss")
 
That is what I use to do basic timing on routines where pinpoint accuracy is
not necessary, and is at least the equal of the Now function IMO.

If you want greater accuracy, you need a better timer, such as Karl
Petersens's CCRP Timer http://vb.mvps.org/tools/ccrpTmr/

--

HTH

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

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

Back
Top