Hi All,
i need to built a tracker where user input two time stamps Like - 10:25:35 and 12:22:33 in excle through User form and the output should be the diffrence between input time. user input time in three text boxes - for Hour,Minute and secs respectively
Dim loginT, logout, logoutT, totalT As Date
loginT = txtLTHH.Text & ":" & txtLTMM.Text & ":" & txtLTSS.Text
logout = txtLOHH.Text & ":" & txtLOMM.Text & ":" & txtLOSS.Text
but when i pass this parameter in my UDF it generates type mismatch Error.
Logout = MinusTime(LogoutT,LoginT) 'Type Mismatch error.
UDF -
Public Function MinusTime(t1 As Date, t2 As Date) As String
Dim T1sec As Double
Dim T2sec As Double
Dim totalsecs As Double
Dim h As Double
Dim m As Double
Dim s As Double
Dim final As String
T1sec = (Hour(t1) * 60 * 60) + (Minute(t1) * 60) + Second(t1)
T2sec = (Hour(t2) * 60 * 60) + (Minute(t2) * 60) + Second(t2)
If T1sec < T2sec Then
final = "00:00:00"
Else
totalsecs = T1sec - T2sec
h = (totalsecs Mod 86400) \ 3600
m = ((totalsecs Mod 86400) Mod 3600) \ 60
s = ((totalsecs Mod 86400) Mod 3600) Mod 60
final = VBA.Format(h, "00") & ":" & VBA.Format(m, "00") & ":" & VBA.Format(s, "00")
End If
MinusTime = final
End Function
Please help.........
i need to built a tracker where user input two time stamps Like - 10:25:35 and 12:22:33 in excle through User form and the output should be the diffrence between input time. user input time in three text boxes - for Hour,Minute and secs respectively
Dim loginT, logout, logoutT, totalT As Date
loginT = txtLTHH.Text & ":" & txtLTMM.Text & ":" & txtLTSS.Text
logout = txtLOHH.Text & ":" & txtLOMM.Text & ":" & txtLOSS.Text
but when i pass this parameter in my UDF it generates type mismatch Error.
Logout = MinusTime(LogoutT,LoginT) 'Type Mismatch error.
UDF -
Public Function MinusTime(t1 As Date, t2 As Date) As String
Dim T1sec As Double
Dim T2sec As Double
Dim totalsecs As Double
Dim h As Double
Dim m As Double
Dim s As Double
Dim final As String
T1sec = (Hour(t1) * 60 * 60) + (Minute(t1) * 60) + Second(t1)
T2sec = (Hour(t2) * 60 * 60) + (Minute(t2) * 60) + Second(t2)
If T1sec < T2sec Then
final = "00:00:00"
Else
totalsecs = T1sec - T2sec
h = (totalsecs Mod 86400) \ 3600
m = ((totalsecs Mod 86400) Mod 3600) \ 60
s = ((totalsecs Mod 86400) Mod 3600) Mod 60
final = VBA.Format(h, "00") & ":" & VBA.Format(m, "00") & ":" & VBA.Format(s, "00")
End If
MinusTime = final
End Function
Please help.........
Last edited: