VBA Timer with rolling list

DutchDisaster

New Member
Joined
Apr 3, 2018
Messages
5
What I was asked to do is to create a countdown timer that starts with the first value in a predetermined list of roundtrip times, and when it reaches zero, it has to move on to the next value and so on, till the list has been completed and then stop. This list with time values will eventually be created daily in another file (on another machine), but will be imported in the timer file each morning.

One thing to remember; this list of times is variable, i.e. it runs from 0800h to 1630h, but due to roundtrips being longer or shorter depending on the required schedule, the amount of roundtrips can change each day.

I have built the timer, which works as required, but I am at a loss how to feed the timer the next value in the list. Right now, the timer uses cell E4 for its starting value, so I'd need the new value to appear there at the end of each cycle.

This is my timer at the moment:

Code:
Public Countdown As Double

Sub StartCountdown()
    Countdown = Now + TimeSerial(0, 0, 1)
    Application.OnTime earliestTime:=Countdown, procedure:="RunCountdown", _
         schedule:=True
End Sub

Sub RunCountdown()
    Sheet2.Range("B2").Value = Sheet2.Range("B2").Value - TimeValue("00:00:01")
    If Sheet2.Range("B2").Value >= TimeValue("12:00:00") Then
        Call StopCountdown
        Range("B2") = Range("F20")
        Exit Sub
    End If
    If Sheet2.Range("B2").Value <= 0 Then
        Range("B2") = Range("E4")
    End If
    StartCountdown
End Sub

Sub StopCountdown()
    On Error Resume Next
    Application.OnTime earliestTime:=Countdown, _
        procedure:="RunCountdown", schedule:=False
End Sub

This is my test setup:

BCDEF
1
200:00:000,0000
3
412:00:0100:15:00
500:14:00
600:13:00
700:12:00
800:11:00
900:10:00
1000:09:00
1100:08:00
1200:07:00
1300:06:00
1400:05:00
1500:04:00
1600:01:00
1700:00:30
1800:00:10
1900:00:01
2000:00:00
2112:00:01

<tbody>
</tbody>
Sheet2
The bottom value in the list is over 12h, as it is the trigger to stop. The generated lists will all have the 12:00:01 value as the last value to stop the countdown sequence. D2 is related to that (used to generate a value in B2 of 00:00:00 after the countdown ends). At the moment, E4 has a simple dropdown list, which is (F4:F21).

So what I need now are suggestions on how to create the rolling list I'm missing.

I'm thinking the required code should be inserted somewhere in the RunCountdown sub?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,938
Latest member
Aaliya13

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top