Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Record time peroid to run code

Hi

Is there a msgbox method that will record the length of time it take for
code to complete its execution.

Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,722
Default Record time peroid to run code

Sub TestTime()
Dim StartTime As Single
StartTime = Timer

'do code here

MsgBox "Code took " & Timer - StartTime & " seconds"
End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"gotroots" wrote:

Hi

Is there a msgbox method that will record the length of time it take for
code to complete its execution.

Thank you.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Record time peroid to run code

The topic is very well covered he

http://support.microsoft.com/kb/q172338
--
Gary''s Student - gsnu200909


"gotroots" wrote:

Hi

Is there a msgbox method that will record the length of time it take for
code to complete its execution.

Thank you.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Record time peroid to run code

Hi,

Timer is the number of seconds since midnight so this will fail if the code
runs over midnight

Dim runtime As Long
Start = Timer
'Your code
MsgBox = Timer - Start


Mike

"gotroots" wrote:

Hi

Is there a msgbox method that will record the length of time it take for
code to complete its execution.

Thank you.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Record time peroid to run code

it would help if I read my code before posting it:(

Try this instead


Start = Timer
'Your code

MsgBox Timer - Start


Mike


"Mike H" wrote:

Hi,

Timer is the number of seconds since midnight so this will fail if the code
runs over midnight

Dim runtime As Long
Start = Timer
'Your code
MsgBox = Timer - Start


Mike

"gotroots" wrote:

Hi

Is there a msgbox method that will record the length of time it take for
code to complete its execution.

Thank you.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Record time peroid to run code

Sub do_things()

StartTime = Timer

'do things

MsgBox Timer - StartTime

End Sub


Gord Dibben MS Excel MVP


On Fri, 8 Jan 2010 12:16:02 -0800, gotroots
wrote:

Hi

Is there a msgbox method that will record the length of time it take for
code to complete its execution.

Thank you.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Record time peroid to run code

Hi folks
Thanks for all the advice.

I went for Mike H. approach as it will deal with the midnight issue.

My test returned 1786.469

It would be helpful if the result can be in the hh:mm:ss format.

Thank you

"Mike H" wrote:

it would help if I read my code before posting it:(

Try this instead


Start = Timer
'Your code

MsgBox Timer - Start


Mike


"Mike H" wrote:

Hi,

Timer is the number of seconds since midnight so this will fail if the code
runs over midnight

Dim runtime As Long
Start = Timer
'Your code
MsgBox = Timer - Start


Mike

"gotroots" wrote:

Hi

Is there a msgbox method that will record the length of time it take for
code to complete its execution.

Thank you.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Record time peroid to run code

In all the other replies, don't use Timer, use Time(). Then even if it takes
days, it will be accurate.

--
* Please click Yes if this was helpful *
Andy Smith
Senior Systems Analyst
Standard & Poor''s, NYC



"gotroots" wrote:

Hi

Is there a msgbox method that will record the length of time it take for
code to complete its execution.

Thank you.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Record time peroid to run code

Try this:
MsgBox Format(Timer - Start,"HH:MM:SS")

Sometimes I want to check several substeps, in which case (just out of
habit) I tend to use:

Time1 = now()
'do code
Time2 = now()
'more code
Time3=now()
etc.

then just use any combo of those, such as
msgbox "Part 1: " & Format(Time2-Time1,"HH:MM:SS") & chr(13) & _
"Part 2: " & Format(Time3-Time2,"HH:MM:SS")

and so on.

HTH,
Keith

"gotroots" wrote:

Hi folks
Thanks for all the advice.

I went for Mike H. approach as it will deal with the midnight issue.

My test returned 1786.469

It would be helpful if the result can be in the hh:mm:ss format.

Thank you

"Mike H" wrote:

it would help if I read my code before posting it:(

Try this instead


Start = Timer
'Your code

MsgBox Timer - Start


Mike


"Mike H" wrote:

Hi,

Timer is the number of seconds since midnight so this will fail if the code
runs over midnight

Dim runtime As Long
Start = Timer
'Your code
MsgBox = Timer - Start


Mike

"gotroots" wrote:

Hi

Is there a msgbox method that will record the length of time it take for
code to complete its execution.

Thank you.

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Record time peroid to run code

didn't do too much testing, but see if this works for you:

dim startTime as date
dim endTime as date
dim tTime as date
starttime = Now()
' your code
endTime = Now()
tTime = (endTime - startTime) * 86400
Debug.Print WorksheetFunction.Floor(tTime / 60, 1) & " minutes " & tTime Mod 60
& " seconds"

or you can use a msgbox instead of the debug.print statement

msgbox WorksheetFunction.Floor(tTime / 60, 1) & " minutes " & tTime Mod 60 & "
seconds"

--


Gary Keramidas
Excel 2003


"gotroots" wrote in message
...
Hi folks
Thanks for all the advice.

I went for Mike H. approach as it will deal with the midnight issue.

My test returned 1786.469

It would be helpful if the result can be in the hh:mm:ss format.

Thank you

"Mike H" wrote:

it would help if I read my code before posting it:(

Try this instead


Start = Timer
'Your code

MsgBox Timer - Start


Mike


"Mike H" wrote:

Hi,

Timer is the number of seconds since midnight so this will fail if the code
runs over midnight

Dim runtime As Long
Start = Timer
'Your code
MsgBox = Timer - Start


Mike

"gotroots" wrote:

Hi

Is there a msgbox method that will record the length of time it take for
code to complete its execution.

Thank you.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Record time by formula karim Excel Worksheet Functions 10 April 29th 10 01:36 PM
How do you print 1 record at a time per page? Greg Excel Discussion (Misc queries) 5 March 23rd 09 09:24 PM
Daily Time Record shiela21cute Excel Programming 1 April 7th 06 12:54 PM
Retrieve and update 1 record at a time Markantesp Excel Programming 2 March 7th 05 06:35 AM
A stopwatch to record time in a cell Gabe Excel Programming 3 September 2nd 04 03:04 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"