I have implemented a count-down timer which is now working for whole minutes entered into a text box by the user (e.g. 05:00), however I am struggling with implementing functionality for the user to enter their own seconds as well.
The userform has a button "Timercustom", when clicked a routine will update every second a text box "TextBox3" in the format 00:00 (e.g.05:00) to countdown from the initial to 00:00.
Could someone with more VBA experience help to make adjustments so that extra seconds that are added are counted down as well? I have tried several hours to do this, but stripped back to the working code below for whole minutes only for clarity.
'Initialisation function
Private Sub UserForm_Initialize()
Dim M As Double, S As Double
M = Int(CDbl(AllowedTime))
S = (CDbl(AllowedTime) - Int(CDbl(AllowedTime))) * 60
With TextBox1
.Value = Format(CStr(M), "15") & ":" & Format(CStr(S), "00")
End With
With TextBox2
.Value = Format(CStr(M), "45") & ":" & Format(CStr(S), "00")
End With
With TextBox3
.Value = Format(CStr(M), "5") & ":" & Format(CStr(S), "00")
End With
End Sub
'main function to start the timer
Private Sub Timercustom_Click()
Dim t, E, M As Double, S As Double
Dim AllowedTime As Integer
Dim TextStrng As String
Dim Result() As String
Dim tempS As Double
Dim firstRun As Boolean
firstRun = True
TextStrng = TextBox3.Value
Result() = Split(TextStrng, ":")
AllowedTime = Result(0)
t = Timer
Do
If Timer - t < 0 Then
Unload UserForm1
MsgBox "Error encountered - start again"
Exit Sub
End If
E = CDbl(Time) * 24 * 60 * 60 - t 'elapsed time in secs
M = (CDbl(AllowedTime) - 1) - Int(E / 60)
'this just avoids a weirdity where the seconds initially goes to 00:0-1, for some reason
If tempS < 0 Then
tempS = Result(1)
End If
S = tempS
With TextBox3
.Value = Format(CStr(M), "00") & ":" & Format(CStr(S), "00")
End With
DoEvents
Loop Until (Timer - t) / 60 >= CDbl(AllowedTime) Or UserForm1.Visible = False
End Sub

Dim t, E, M As DoublethattandEare of typeVariantyou must specify a type for every variable:Dim t As Double, E As Double, M As DoubleAllowedTimeis defined inTimercustom_Clickbut used inUserForm_Initialize. Always useOption Explicitto check variable declarations.