Gregorys05
Board Regular
- Joined
- Sep 24, 2008
- Messages
- 217
Hi guys,
I have the below function that calculates time in hours and mins if you type in seconds.
e.g 1200 secs - formula : =calctime(1200) cell value: 20:00
The problem i have is that if i have two columns with the formula in that i want to sum i cannot do this by just using the sum function.
Any ideas how i can do this at all??
Thanks
I have the below function that calculates time in hours and mins if you type in seconds.
e.g 1200 secs - formula : =calctime(1200) cell value: 20:00
The problem i have is that if i have two columns with the formula in that i want to sum i cannot do this by just using the sum function.
Any ideas how i can do this at all??
Thanks
Code:
Function CalcTime(Seconds) As String
Dim tData1, tData2
If Not IsNumeric(Seconds) Then Exit Function
If Seconds < 60 Then
If Len(Seconds) = 1 Then
CalcTime = "00:0" & Seconds
Else
CalcTime = "00:" & Seconds
End If
Else
tData1 = RoundDown(Seconds / 60)
tData2 = Seconds - tData1 * 60
If Len(tData1) = 1 Then
tData1 = "0" & tData1
End If
If Len(tData2) = 1 Then
tData2 = "0" & tData2
End If
CalcTime = tData1 & ":" & tData2
End If
End Function
Function RoundDown(Number)
Dim tData1
tData1 = InStr(Number, ".")
If tData1 = 0 Then
RoundDown = Number
Else
RoundDown = Left(Number, tData1 - 1)
End If
End Function