0
Thanks

A few words of thanks would be greatly appreciated.

VBA A simple second Timer


In the VBA, a simple second timer is easy to write and include in the source code. The VBA comes with a full-featured timer which can be used whenever required. However, it is not compulsory to use the timer provided with the VBA. Timer control in the VBA can be done through a manual timer too. It is not a complicated task to create a manual timer function in the VBA. One needs to write the code to create a timer in a public module. With the VBA, a simple second timer can be created to enhance and customize the Office software especially for Excel worksheets.



In VBA there is Timer feature available, but you can also create one very easily.

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


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
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Related

This document, titled « VBA A simple second Timer », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

2 Comments