VBA Timer

The VBA Timer function returns a Single numeric value representing the number of seconds elapsed since midnight on the current day.

If you want to pause code execution for duration of time check out the VBA Sleep and Application.Wait functions instead.

VBA Timer Function Syntax

The syntax for the Timer function in VBA is:


The Timer function does not accept any parameters.

Example usage

The VBA Timer function can be used in VBA code. Let’s look at some VBA Timer function examples:

Measure elapsed time in Seconds

Debug.Print Timer()
'Result (at 11:55 AM): 42839,02  

Dim startTime as Single

startTime = Timer
'... Some code here ...
Debug.Print Timer - startTime 
'Result: time in seconds elapsed

Measure elapsed time in Hours / Minutes / Seconds

As the VBA Timer function measures time elapsed in seconds, if we want minutes or hours instead we may need to tweak it:

Dim startTime as Single, timeElapsed as Single, hours as Long, min as Long, seconds as Single

startTime = Timer 'Get current time
'... Some code here ...
timeElapsed = Timer - startTime 'Save the elapsed time to timeElapsed variable

'Extract hours
hours = timeElapsed / 3600
timeElapsed = timeElapsed - hours * 3600

'Extract minutes
mins = timeElapsed / 60
timeElapsed = timeElapsed - mins * 60

'Extract seconds
seconds = timeElapsed

Debug.Print "Time Elapsed: " & hours & " hours, " & mins & " minutes, " & seconds & " seconds"