Timing code secitions

W

Wombat

For Excel VBA code that takes many minutes to execute I
want to record the start time and finish for loop. Then
I will output the difference to a worksheet. I can't seem
to get the syntax to work; for example to put the time in
the variable I tried
start_time = Application.Run("Now()") or
start_time = WorksheetFunction("Now()")
If I could do this I then need to calculate how many
seconds in finish_time - start_time.

Can anyone help please.
Thanks
 
O

Oneide

Maybe you should try:

Dim start_time As Date
start_time = Now()

Is that good enough?
 
O

Oneide

For me, both works ...
But I prefer with the parenthesis, cause it's a function returning a value
(some kink of C's style) and not just a variable or constant. Or is it?

Dick Kusleika <[email protected]> escreveu nas notícias de
mensagem:eWrt#[email protected]...
| start_time = Now
|
| No parentheses in VBA
|
| --
| Dick Kusleika
| MVP - Excel
| www.dicks-clicks.com
| Post all replies to the newsgroup.
 
D

Dick Kusleika

You're right, it is a function. By using the parentheses, you're passing it
no value and I'm just omitting any argument. I like your reasoning for your
preference though. It will probably make the code more readable.
 
D

Dave

Use the 'Timer' function for more acurate timing.
<snip>"Returns a Single representing the number of seconds elapsed since
midnight.</snip>

hth,
Dave

public function foo()
Dim tmpSng As Single

tmpSng = Timer
'........
MsgBox Round(Timer - tmpSng, 5)

end function
 

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

Top