Find value (time) in a range and apply a condition

Simona

New Member
Joined
Aug 9, 2010
Messages
13
Hi,
I’m new to the board and I need some help.
I have 3 columns in Excel with the “Train number”, “Route” and “Time of departure” and I need to allocate the trains (4th column) using a list of meals according to the time of departure:
<table class="MsoNormalTable" style="width: 314pt; margin-left: 4.65pt; border-collapse: collapse;" border="0" cellpadding="0" cellspacing="0" width="419"> <tbody><tr style="height: 15pt;"> <td style="width: 107.1pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="143"> Route<o:p></o:p>
</td> <td colspan="2" style="width: 114.4pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="153" nowrap="nowrap">
Time Range<o:p></o:p>
</td> <td style="width: 69.85pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="93" nowrap="nowrap"> Meal<o:p></o:p>
</td> <td style="width: 22.65pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="30" nowrap="nowrap">
</td> </tr> <tr style="height: 15pt;"> <td style="width: 107.1pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="143"> ALL <o:p></o:p>
</td> <td style="width: 49.6pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="66" nowrap="nowrap">
00:00:00<o:p></o:p>
</td> <td style="width: 64.8pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="86" nowrap="nowrap">
09:29:00<o:p></o:p>
</td> <td style="width: 69.85pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="93" nowrap="nowrap"> BKF<o:p></o:p>
</td> <td style="width: 22.65pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="30" nowrap="nowrap">
</td> </tr> <tr style="height: 15pt;"> <td style="width: 107.1pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="143"> ALL <o:p></o:p>
</td> <td style="width: 49.6pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="66" nowrap="nowrap">
09:30:00<o:p></o:p>
</td> <td style="width: 64.8pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="86" nowrap="nowrap">
10:59:00<o:p></o:p>
</td> <td style="width: 69.85pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="93" nowrap="nowrap"> BKF+<o:p></o:p>
</td> <td style="width: 22.65pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="30" nowrap="nowrap">
</td> </tr> <tr style="height: 15pt;"> <td style="width: 107.1pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="143"> ALL<o:p></o:p>
</td> <td style="width: 49.6pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="66" nowrap="nowrap">
11:00:00<o:p></o:p>
</td> <td style="width: 64.8pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="86" nowrap="nowrap">
13:59:00<o:p></o:p>
</td> <td style="width: 69.85pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="93" nowrap="nowrap"> DTM<o:p></o:p>
</td> <td style="width: 22.65pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="30" nowrap="nowrap">
</td> </tr> <tr style="height: 15pt;"> <td style="width: 107.1pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="143"> LISBON<o:p></o:p>
</td> <td style="width: 49.6pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="66" nowrap="nowrap">
14:00:00<o:p></o:p>
</td> <td style="width: 64.8pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="86" nowrap="nowrap">
16:29:00<o:p></o:p>
</td> <td style="width: 69.85pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="93" nowrap="nowrap"> ALM<o:p></o:p>
</td> <td style="width: 22.65pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="30" nowrap="nowrap">
</td> </tr> <tr style="height: 15pt;"> <td style="width: 107.1pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="143"> MADRID<o:p></o:p>
</td> <td style="width: 49.6pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="66" nowrap="nowrap">
14:00:00<o:p></o:p>
</td> <td style="width: 64.8pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="86" nowrap="nowrap">
17:29:00<o:p></o:p>
</td> <td style="width: 69.85pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="93" nowrap="nowrap"> ALM<o:p></o:p>
</td> <td style="width: 22.65pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="30" nowrap="nowrap">
</td> </tr> <tr style="height: 15pt;"> <td style="width: 107.1pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="143"> LISBON<o:p></o:p>
</td> <td style="width: 49.6pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="66" nowrap="nowrap">
16:30:00<o:p></o:p>
</td> <td style="width: 64.8pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="86" nowrap="nowrap">
23:59:00<o:p></o:p>
</td> <td style="width: 69.85pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="93" nowrap="nowrap"> DIN<o:p></o:p>
</td> <td style="width: 22.65pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="30" nowrap="nowrap">
</td> </tr> <tr style="height: 15pt;"> <td style="width: 107.1pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="143"> MADRID<o:p></o:p>
</td> <td style="width: 49.6pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="66" nowrap="nowrap">
17:30:00<o:p></o:p>
</td> <td style="width: 64.8pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="86" nowrap="nowrap">
23:59:00<o:p></o:p>
</td> <td style="width: 69.85pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="93" nowrap="nowrap"> DIN<o:p></o:p>
</td> <td style="width: 22.65pt; padding: 0cm 5.4pt; height: 15pt;" valign="bottom" width="30" nowrap="nowrap">
</td> </tr> </tbody></table> <o:p> </o:p>
Question 1: which formula should I use in order to return the meal for a train that, for example, departures at 9:54 as I have only the time ranges?
Question 2: solved the problem above, how can I make it work including the route (as you can see on the table the time range for the meals changes according to the route).
Thank you for your help!
NB: Better if not VBA
Simona
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
In your example, if the word "Route" is in A1, and you want to get the info from a time entered in F3, for example:
Q1: =VLOOKUP(F3,B2:D10,3)
Q2: =LOOKUP(F3,B2:B10,A2:A10)

HTH
 
Upvote 0
Great!!!
in the Q1 I was always using the criteria "False" at the end of the vlookup formula which returns only exactly matches! Take it off and it will work perfectly with ranges.
For the second question the lookup formula is not enough but I used a nested "if" and now it's working nice!!!
Many thanks!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,760
Members
449,095
Latest member
m_smith_solihull

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