I have the following function thats takes a cell value in the format 0700-1900 and calculates the number of hours elapsed. It works fine but I would like to be able to use a range of cells as the parameter and work through the cells to get the total hours. Can someone point me in the right direction.
Cheers, Craig
Si fractum non sit, noli id reficere
Code:
Public Function totalHours(t1 As String)
'
' Input T1: 24-hour time as integer,e.g., 1130=11:30, 1650=16:50
' Output, time as serial time e.g, 0.5 for noon.
'
Dim tt1 As Double
Dim time1 As Double
Dim time2 As Double
If IsNumeric(Left(t1, 4)) Then
time1 = Left(t1, 4)
time2 = Right(t1, 4)
If time1 < time2 Then
tt1 = (Int(time2 / 100) + (((time2 / 100) - Int(time2 / 100)) / 0.6)) _
- (Int(time1 / 100) + (((time1 / 100) - Int(time1 / 100)) / 0.6))
Else: tt1 = ((Int(time2 / 100) + (((time2 / 100) - Int(time2 / 100)) / 0.6)) + 24) _
- (Int(time1 / 100) + (((time1 / 100) - Int(time1 / 100)) / 0.6))
End If
tt1 = tt1 / 24
totalHours = tt1
Else: totalHours = 0
End If
End Function
Cheers, Craig
Si fractum non sit, noli id reficere