Time consumption in macros

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi eveybody, here I am with one question:

How can I know the time which takes to Excel to execute a macro. Because I
have got some loops and I want to know how long does it take in order to view
if I can improve the loops or not.

Probably it is a simple question which I don't know and I think it is very
useful.

Thanks for your time!!!
 
At the start of your code put in the line:

start_time = Now


and at the end put:

msgbox "Seconds elapsed: " & int((now-start_time)*86400)


Col
 
Jon,

Here's a quick one.

Sub YourSubName()
Dim starttime As Double
starttime = Now
....your code....
MsgBox (Format(Now - starttime, "h:mm:ss"))
End Sub


Mike
 
You want to use the timer something like this...

Dim lng As Long
Dim sngStartTime As Single
Dim sngEndTime As Single

sngStartTime = Timer
For lng = 1 To 1000000000 Step 1
Next lng
sngEndTime = Timer
MsgBox "Duration " & sngEndTime - sngStartTime
 
As an example, rough and ready but should suit

Dim i As Long, j As Long
Dim nTime As Double

nTime = Timer
For i = 1 To 10000
For j = 1 To 10000
'
Next j
Next i

MsgBox Timer - nTime

--
HTH

Bob Phillips

(replace somewhere in email address with gmail 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