ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Time consumption in macros (https://www.excelbanter.com/excel-programming/366978-time-consumption-macros.html)

Jon

Time consumption in macros
 
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!!!

colofnature[_83_]

Time consumption in macros
 

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


--
colofnature
------------------------------------------------------------------------
colofnature's Profile: http://www.excelforum.com/member.php...o&userid=34356
View this thread: http://www.excelforum.com/showthread...hreadid=560703


Jim Thomlinson

Time consumption in macros
 
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
--
HTH...

Jim Thomlinson


"Jon" wrote:

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!!!


crazybass2

Time consumption in macros
 
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

"Jon" wrote:

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!!!


Bob Phillips

Time consumption in macros
 
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)

"Jon" wrote in message
...
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!!!




Jon

Time consumption in macros
 
Really thanks to all of you. It has been very useful.

"Bob Phillips" wrote:

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)

"Jon" wrote in message
...
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!!!






All times are GMT +1. The time now is 07:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com