VBA Function: Timer

The VBA Timer function returns the number of seconds elapsed since midnight.



Examples of Usage

Example of value returned by the Timer function:

Sub example()

    MsgBox Timer 'Returns, for example: 55036.16
End Sub

Using the Timer function to calculate the execution time of a procedure:

Sub example()
    'Timer at the beginning of the procedure
    timerBefore = Timer
    'Pause (for example purposes)
    Application.Wait Now + TimeValue("0:00:02")
    'Display the duration of the procedure
    MsgBox "Execution time: " & Timer - timerBefore & " seconds."
End Sub
timer excel vba duration execution