Formula referencing time ranges

RLCornish

New Member
Joined
Feb 11, 2014
Messages
42
I need to create a formula influenced by arrival and departure times. Each individual will come and go at their allotted times. We are working within windows of time. For example, people coming between 8 a.m. and noon and departing between 11 a.m. and 3 p.m. will be on a specific schedule. There are 3 potential windows for arrivals and departures, so 9 potential schedules. The matrix is below. My end game is to populate what schedule an individual is on based on their arrival and departure being between specific ranges. The function will translate to better than 300 individuals so you can imagine we do not want to have to manually figure out which schedule for each person.

I've fiddled with IF's and can get it to work for a single line of the below matrix, and could probably nest all of it, but it would be ugly. I feel like INDEX/MATCH should be a good option, but cannot figure out how to make the "matches" work because of the time ranges. I'm stumped and would very much appreciate some help.


Below this table are the attendees actual arrival and departure times...

[TABLE="class: grid, width: 473"]
<tbody>[TR]
[TD]Earliest Arrival[/TD]
[TD]Latest Arrival[/TD]
[TD]Earliest Departure[/TD]
[TD]Latest Departure[/TD]
[TD]Schedule[/TD]
[/TR]
[TR]
[TD]8:00 AM[/TD]
[TD]12:00 PM[/TD]
[TD]11:00 AM[/TD]
[TD]3:00 PM[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]12:01 PM[/TD]
[TD]4:00 PM[/TD]
[TD]11:00 AM[/TD]
[TD]3:00 PM[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]4:01 PM[/TD]
[TD]10:00 PM[/TD]
[TD]11:00 AM[/TD]
[TD]3:00 PM[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]8:00 AM[/TD]
[TD]12:00 PM[/TD]
[TD]3:01 PM[/TD]
[TD]6:00 PM[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]12:01 PM[/TD]
[TD]4:00 PM[/TD]
[TD]3:01 PM[/TD]
[TD]6:00 PM[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]4:01 PM[/TD]
[TD]10:00 PM[/TD]
[TD]3:01 PM[/TD]
[TD]6:00 PM[/TD]
[TD]F[/TD]
[/TR]
[TR]
[TD]8:00 AM[/TD]
[TD]12:00 PM[/TD]
[TD]6:01 PM[/TD]
[TD]9:00 PM[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD]12:01 PM[/TD]
[TD]4:00 PM[/TD]
[TD]6:01 PM[/TD]
[TD]9:00 PM[/TD]
[TD]H[/TD]
[/TR]
[TR]
[TD]4:01 PM[/TD]
[TD]10:00 PM[/TD]
[TD]6:01 PM[/TD]
[TD]9:00 PM[/TD]
[TD]I[/TD]
[/TR]
</tbody>[/TABLE]


[TABLE="class: grid, width: 210"]
<colgroup><col width="121" style="width:91pt"> <col width="89" style="width:67pt"> </colgroup><tbody>[TR]
[TD="width: 121"]Flight Arrival Time[/TD]
[TD="width: 89"]Flight Departure Time[/TD]
[/TR]
[TR]
[TD="align: right"]8:30 AM[/TD]
[TD="align: right"]11:10 AM[/TD]
[/TR]
[TR]
[TD="align: right"]12:05 PM[/TD]
[TD="align: right"]11:10 AM[/TD]
[/TR]
[TR]
[TD="align: right"]4:15 PM[/TD]
[TD="align: right"]11:10 AM[/TD]
[/TR]
[TR]
[TD="align: right"]8:30 AM[/TD]
[TD="align: right"]3:45 PM[/TD]
[/TR]
[TR]
[TD="align: right"]12:05 PM[/TD]
[TD="align: right"]3:45 PM[/TD]
[/TR]
[TR]
[TD="align: right"]4:15 PM[/TD]
[TD="align: right"]3:45 PM[/TD]
[/TR]
[TR]
[TD="align: right"]8:30 AM[/TD]
[TD="align: right"]7:30 PM[/TD]
[/TR]
[TR]
[TD="align: right"]12:05 PM[/TD]
[TD="align: right"]7:30 PM[/TD]
[/TR]
[TR]
[TD="align: right"]4:15 PM[/TD]
[TD="align: right"]7:30 PM[/TD]
[/TR]
[TR]
[TD="align: right"]8:30 AM[/TD]
[TD="align: right"]11:10 AM[/TD]
[/TR]
[TR]
[TD="align: right"]12:05 PM[/TD]
[TD="align: right"]11:10 AM[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][td="bgcolor:#C0C0C0"]
C​
[/td][td="bgcolor:#C0C0C0"]
D​
[/td][td="bgcolor:#C0C0C0"]
E​
[/td][td="bgcolor:#C0C0C0"]
F​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td="bgcolor:#F3F3F3"]
Earliest Arrival
[/td][td="bgcolor:#F3F3F3"]
Latest Arrival
[/td][td="bgcolor:#F3F3F3"]
Earliest Departure
[/td][td="bgcolor:#F3F3F3"]
Latest Departure
[/td][td="bgcolor:#F3F3F3"]
Schedule
[/td][td="bgcolor:#F3F3F3"]
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td]
8:00 AM​
[/td][td]
12:00 PM​
[/td][td]
11:00 AM​
[/td][td]
3:00 PM​
[/td][td]A[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td]
12:01 PM​
[/td][td]
4:00 PM​
[/td][td]
11:00 AM​
[/td][td]
3:00 PM​
[/td][td]B[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td]
4:01 PM​
[/td][td]
10:00 PM​
[/td][td]
11:00 AM​
[/td][td]
3:00 PM​
[/td][td]C[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td]
8:00 AM​
[/td][td]
12:00 PM​
[/td][td]
3:01 PM​
[/td][td]
6:00 PM​
[/td][td]D[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
6​
[/td][td]
12:01 PM​
[/td][td]
4:00 PM​
[/td][td]
3:01 PM​
[/td][td]
6:00 PM​
[/td][td]E[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
7​
[/td][td]
4:01 PM​
[/td][td]
10:00 PM​
[/td][td]
3:01 PM​
[/td][td]
6:00 PM​
[/td][td]F[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
8​
[/td][td]
8:00 AM​
[/td][td]
12:00 PM​
[/td][td]
6:01 PM​
[/td][td]
9:00 PM​
[/td][td]G[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
9​
[/td][td]
12:01 PM​
[/td][td]
4:00 PM​
[/td][td]
6:01 PM​
[/td][td]
9:00 PM​
[/td][td]H[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
10​
[/td][td]
4:01 PM​
[/td][td]
10:00 PM​
[/td][td]
6:01 PM​
[/td][td]
9:00 PM​
[/td][td]I[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
11​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
12​
[/td][td="bgcolor:#F3F3F3"]
Flight Arrival Time
[/td][td][/td][td="bgcolor:#F3F3F3"]
Flight Departure Time
[/td][td][/td][td="bgcolor:#F3F3F3"]
Schedule
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
13​
[/td][td]
8:30 AM​
[/td][td][/td][td]
11:10 AM​
[/td][td][/td][td="bgcolor:#E5E5E5"]A[/td][td]E13: {=INDEX($E$2:$E$10, MATCH(1, (A13 >= $A$2:$A$10) * (A13 <= $B$2:$B$10) * (C13 >= $C$2:$C$10) * (C13 <= $D$2:$D$10), 0))}[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
14​
[/td][td]
12:05 PM​
[/td][td][/td][td]
11:10 AM​
[/td][td][/td][td="bgcolor:#E5E5E5"]B[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
15​
[/td][td]
4:15 PM​
[/td][td][/td][td]
11:10 AM​
[/td][td][/td][td="bgcolor:#E5E5E5"]C[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
16​
[/td][td]
8:30 AM​
[/td][td][/td][td]
3:45 PM​
[/td][td][/td][td="bgcolor:#E5E5E5"]D[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
17​
[/td][td]
12:05 PM​
[/td][td][/td][td]
3:45 PM​
[/td][td][/td][td="bgcolor:#E5E5E5"]E[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
18​
[/td][td]
4:15 PM​
[/td][td][/td][td]
3:45 PM​
[/td][td][/td][td="bgcolor:#E5E5E5"]F[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
19​
[/td][td]
8:30 AM​
[/td][td][/td][td]
7:30 PM​
[/td][td][/td][td="bgcolor:#E5E5E5"]G[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
20​
[/td][td]
12:05 PM​
[/td][td][/td][td]
7:30 PM​
[/td][td][/td][td="bgcolor:#E5E5E5"]H[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
21​
[/td][td]
4:15 PM​
[/td][td][/td][td]
7:30 PM​
[/td][td][/td][td="bgcolor:#E5E5E5"]I[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
22​
[/td][td]
8:30 AM​
[/td][td][/td][td]
11:10 AM​
[/td][td][/td][td="bgcolor:#E5E5E5"]A[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
23​
[/td][td]
12:05 PM​
[/td][td][/td][td]
11:10 AM​
[/td][td][/td][td="bgcolor:#E5E5E5"]B[/td][td][/td][/tr]
[/table]
 
Upvote 0
Alternatively, you can create a function through VBA & use it in your worksheet directly as =FindSchedule( select arrival time cell, select departure time cell )


Code:
Function FindSchedule(Arrival As Date, Departure As Date) As String

Application.Volatile

    If (Arrival >= #8:00:00 AM# And Arrival <= #12:00:00 PM#) And (Departure >= #11:00:00 AM# And Departure <= #3:00:00 PM#) Then
        FindSchedule = "A"
ElseIf (Arrival >= #12:01:00 PM# And Arrival <= #4:00:00 PM#) And (Departure >= #11:00:00 AM# And Departure <= #3:00:00 PM#) Then
        FindSchedule = "B"
ElseIf (Arrival >= #4:01:00 PM# And Arrival <= #10:00:00 PM#) And (Departure >= #11:00:00 AM# And Departure <= #3:00:00 PM#) Then
        FindSchedule = "C"
        
ElseIf (Arrival >= #8:00:00 AM# And Arrival <= #12:00:00 PM#) And (Departure >= #3:01:00 PM# And Departure <= #6:00:00 PM#) Then
        FindSchedule = "D"
ElseIf (Arrival >= #12:01:00 PM# And Arrival <= #4:00:00 PM#) And (Departure >= #3:01:00 PM# And Departure <= #6:00:00 PM#) Then
        FindSchedule = "E"
ElseIf (Arrival >= #4:01:00 PM# And Arrival <= #10:00:00 PM#) And (Departure >= #3:01:00 PM# And Departure <= #6:00:00 PM#) Then
        FindSchedule = "F"
        
ElseIf (Arrival >= #8:00:00 AM# And Arrival <= #12:00:00 PM#) And (Departure >= #6:01:00 PM# And Departure <= #9:00:00 PM#) Then
        FindSchedule = "G"
ElseIf (Arrival >= #12:01:00 PM# And Arrival <= #4:00:00 PM#) And (Departure >= #6:01:00 PM# And Departure <= #9:00:00 PM#) Then
        FindSchedule = "H"
ElseIf (Arrival >= #4:01:00 PM# And Arrival <= #10:00:00 PM#) And (Departure >= #6:01:00 PM# And Departure <= #9:00:00 PM#) Then
        FindSchedule = "I"
Else: FindSchedule = "Out of timing range"
End If

End Function
 
Upvote 0
That's an interesting piece of VBA code, mse330. I have another project I'm working on where this could be very helpful. Thank you for this.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top