View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob van Gelder[_4_] Rob van Gelder[_4_] is offline
external usenet poster
 
Posts: 1,236
Default Complicated Time Formula

Try this user defined function:

A2 = 09:15
B2 = 11:30
C1 = 09:00
D1 = 10:00
E1 = 11:00
F1 = 12:00
C2 = =PeriodExposure($A2,$B2,C$1,D$1)
D2 = =PeriodExposure($A2,$B2,D$1,E$1)
E2 = =PeriodExposure($A2,$B2,E$1,F$1)

Function PeriodExposure(dStart As Date, dEnd As Date, dPeriodStart As Date,
dPeriodEnd As Date) As Date
Dim dtmTemp As Date

If dStart < dPeriodStart And dEnd < dPeriodStart Or _
dStart = dPeriodEnd And dEnd = dPeriodEnd Then
dtmTemp = 0
ElseIf dStart = dPeriodStart And dEnd < dPeriodEnd Then
dtmTemp = dEnd - dStart
ElseIf dStart < dPeriodStart And dEnd < dPeriodEnd Then
dtmTemp = dEnd - dPeriodStart
ElseIf dStart = dPeriodStart And dEnd = dPeriodEnd Then
dtmTemp = dPeriodEnd - dStart
Else
dtmTemp = dPeriodEnd - dPeriodStart
End If
PeriodExposure = dtmTemp
End Function


"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.