Excel VBA Timer Function
Excel VBA Timer Function: The Timer function in VBA returns a Single data type, evaluating the number of seconds that have elapsed since midnight of the current day.
Syntax
Timer ()
Parameter
NA
Return
This function returns a Single data type after evaluating the number of seconds that have elapsed since midnight of the current day.
Example 1
Sub TimerFunction_Example1() ' It will return the number of seconds since midnight Dim secs_val As Single secs_val = Timer() ' The variable secs_val will return 83638.67188 Cells(1, 1).Value = secs_val End Sub
Output
83638.67
Example 2
Sub TimerFunction_Example2() ' It will return the number of seconds since midnight Dim secs_val1 As Single, secs_val2 As Single secs_val1 = Timer() MsgBox (secs_val1 & "seconds") 'returning the next number of seconds since midnight secs_val2 = Timer() MsgBox (secs_val2 & "seconds") 'returing the difference MsgBox ("Time taken to run code:" & vbNewLine & secs_val1 - secs_val2 & " seconds") End Sub
Output