Excel Countdown timer in vb code

A place to discuss anything.
Post Reply
EonSky
Posts: 5
Joined: Tue Mar 24, 2020 10:37 pm

Hi All,

I was wondering if anyone could help me or direct me to where i might be able to find vba code for excel that will do the same as the countdown timer that appears in cell F4 of the excel BetAngel spreadsheets please.

I am developing my own spreaadsheet that does some cashflow orientated calcs and then puts the bet data into the Bet Angel Spreadsheet.

As I am looking at this new spreadsheet mainly, it would save a bit of hassle to where i have to jump over to the other file to see, as well as in the future i want the new spreadsheet to fire the bets over based on this countdown automatically. so it can become fully automatic.

Any help is appreciated and thank you.

Paul
User avatar
ODPaul82
Posts: 818
Joined: Sun May 08, 2011 6:32 am

You could in theory avoid using code by just pointing to F4 in the other workbook?

If you want to go the code way though the following would do it as there isn't an in-built timer event in Excel (have just ripped it from stackoverflow, its not my own)

Code: Select all

Public Declare Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long

Public Declare Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long

Public TimerID As Long, TimerSeconds As Single, tim As Boolean
Dim Counter As Long

'~~> Start Timer
Sub StartTimer()
    '~~ Set the timer for 1 second
    TimerSeconds = 1
    TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
End Sub

'~~> End Timer
Sub EndTimer()
    On Error Resume Next
    KillTimer 0&, TimerID
End Sub

Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
    '~~> Update value in Sheet 1
    Sheet1.Range("A1").Value = Time
End Sub
EonSky
Posts: 5
Joined: Tue Mar 24, 2020 10:37 pm

Thank you ODPaul82, I appreciate it.
Kinds Regards
Post Reply

Return to “General discussion”