View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
shockley shockley is offline
external usenet poster
 
Posts: 135
Default Complicated Time Formula

Jay, Here's my offering:

Put a column of 24 cells somewhere on the worksheet with the values 0 to 23
and name it "Intervals" (I think range names are case sensitive, so be sure
your case matches the one in the macro).

Name the 2-cell range with the two input cells "TimeInput".

Name the 24-cell range adjacent (to the right) to the "Intervals" range
"Results".

Run this macro for each set of inputs:

HTW,
Shockley

Private arr(1 To 24, 2) As Integer
Sub Tester()
Range("Results").ClearContents
Erase arr
BeginTime = Range("TimeInput").Cells(1)
EndTime = Range("TimeInput").Cells(2)
HourSpan = Hour(EndTime) - Hour(BeginTime)
If HourSpan 0 Then
arr(1, 1) = Hour(BeginTime)
arr(1, 2) = 60 - Minute(BeginTime)
arr(2, 1) = Hour(EndTime)
arr(2, 2) = Minute(EndTime)
Else
arr(1, 1) = Hour(BeginTime)
arr(1, 2) = Minute(EndTime) - Minute(BeginTime)
End If
x = 2
If HourSpan 1 Then
For i = Hour(BeginTime) + 1 To Hour(EndTime) - 1
x = x + 1
arr(x, 1) = i
arr(x, 2) = 60
Next i
End If
EnterData
End Sub
Sub EnterData()
For i = 1 To 24
If arr(i, 1) = Empty Then Exit Sub
Range("Intervals").Find( _
What:=arr(i, 1), _
LookIn:=xlValues) _
.Offset(0, 1) _
= arr(i, 2)
Next i
End Sub



"Jay" wrote in message
...
I have a comlicated formula that I need to develop and
I'm looking for some help. I have two cells that contain
a start time and an end time. I need to calculate the
total time between the two times and place the value into
the approipriate time slot. i.e. if the start time is
09:15 and the end time is 11:30 the value in the 09-10
cell would be 45 and the value in the 10-11 cell would be
60, and the value in the 11-12 cell would be 30. Any
ideas or hints. Thank you.