Forum Discussion

richzip505's avatar
richzip505
Copper Contributor
Apr 25, 2024
Solved

Look for dates/times that are closest to specified date/time

Hello everyone,   In my worksheet, I have a list of events that I need to schedule flights for (both to and from the event).  The flights to be scheduled depend on the time of the event, and there ...
  • SnowMan55's avatar
    Apr 26, 2024

    richzip505 

    First, please keep all scheduled flights on the same worksheet.  Doing otherwise would result in formulas that are more complicated and less efficient.


    The solution in the attached workbook requires Excel 365 or Excel for the web.


    Columns D cells will contain essentially the same formula (it can be copied down as needed), and the column J formulas are not much different. Read the _Info worksheet for more information.

     

    Here's the formula from cell D7:

    =LET( desired_route_useful_times, FILTER(Sheet2!$B$2:$D$500,
            (Sheet2!$A$2:$A$500 = B7) * (Sheet2!$D$2:$D$500 <= C7) ),
        sorted_flights, SORT(desired_route_useful_times, 3, -1),
        best_flight, TAKE(sorted_flights, 1),
        IFERROR( best_flight, "" )
    )

    I have used a maximum of about 500 rows.  If you have more flight data than that, those cell references can be readily changed.  Or better, consider replacing the range references with dynamic named ranges; unfortunately, they will be difficult to set up accurately if you include completely empty rows between each route, as in your sample data.

     

Resources