VBA Timer oveflow

J.Ty.

Well-known Member
Joined
Feb 4, 2012
Messages
1,118
Office Version
  1. 365
  2. 2013
  3. 2010
Platform
  1. Windows
  2. Web
I am using VBA Timer function to measure time of various Excel computations, in the spirit of
Code:
        t = Timer
           Worksheets("Example").Calculate
        s = Timer
        elapsed = s - t


However, when it comes to measuring periods of the order of many hours, it overflows and recently I've got negative values of 'elapsed'. Does anybody know the size of the numbers Timer uses, and how to recover the true time from the negative one?

J.Ty.
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
what made it negative, any idea of the length of time that may have been involved

could s have been re-declared by another routine
 
Upvote 0
Hi

How did you declare s and t?

Notice from the help:

Returns a Single representing the number of seconds elapsed since midnight.

Does your period include midnight?
 
Last edited:
Upvote 0
I am using VBA Timer function to measure time of various Excel computations, in the spirit of
Rich (BB code):
        t = Timer
           Worksheets("Example").Calculate
        s = Timer
        elapsed = s - t


However, when it comes to measuring periods of the order of many hours, it overflows and recently I've got negative values of 'elapsed'. Does anybody know the size of the numbers Timer uses, and how to recover the true time from the negative one?

J.Ty.

Timer returns a Single representing the number of seconds elapsed since midnight.

If your calculations elapsed over midnight, then s will be smaller than t

This will add a day (86400 seconds) to s if it's less than t

Rich (BB code):
        t = Timer
           Worksheets("Example").Calculate
        s = Timer
       If s < t then s = s + 86400
        elapsed = s - t
 
Upvote 0
Hi

How did you declare s and t?

Notice from the help:



Does your period include midnight?

Bingo! Midnight was in the middle (the computation should have taken around 11 hours and started late in the afternoon).

Thanks!

J.Ty.
 
Upvote 0

Forum statistics

Threads
1,214,624
Messages
6,120,591
Members
448,973
Latest member
ksonnia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top