How to create a timer in Excel VBA

How to create a timer in Excel VBA

In Excel, you can very easily create your timers using just a few lines of VBA code.

How to create a Timer in a module sheet?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'For example: Start / Stop the timer every time the cell.
    'but may also be placed on a button or another ...
        TimeOnOFF = Not TimeOnOFF
        If TimeOnOFF Then Timer
End Sub

How to create a Timer in a public module?

Public TimeOnOFF As Boolean
Sub Timer()
Dim S As Integer
        While TimeOnOFF = True
            If Second(Now) > S Or Second(Now) = 0 Then
                'Run code '.... 'for example Sheets("shee1").Range("A1").Value = Time
S = Second(Now)
            End If
            DoEvents
        Wend
End Sub

Excel