How to find the next nearest time from array to given time

Paul21

New Member
Joined
Mar 17, 2018
Messages
17
Hello,

I am trying to solve the following problem and your expertise and help would be greatly appreciated :biggrin::
Ho to find the next nearest time from array B5:B36 to date entered by user in E4. (User should enter a time when the freight is ready and formula should pick the next closest date and flight number from the array)
I was experimenting with this formula =INDEX(B5:B36,MATCH(MIN(ABS(B5:B36-E4)),ABS(B5:B36-E4),0))
but it's not working properlyL. I am not sure whether I can use this technique only for time without having dates.
How midnight 00:00:00 will be interpreted.

Really appreciate all the answers and time spent on this:biggrin:!!!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
What format do you use? In te array you have dates as well? So dd/mm/yy hh:mm in E4? If yes,
You could have index match on time(hour(E4),...)

Note that to find the next value, you can use
Code:
match(value,array,-1)
instead of match(,,0)
 
Last edited:
Upvote 0
Hi Kamolga,
Array and E4 should contain time values in hh:mm or HH/MM AM/PM format.
Can you pelase be more specific about the formula to use? Was not able to integrate your propsoal.
Does this dormula can work with values containing only time?
Thank you,
 
Upvote 0
If the times in B5:B36 are sorted

Code:
=INDEX(B5:B36,MATCH(E4,B5:B36)+1)

For some reason, if you asked the time before, it works with

Code:
=INDEX(B5:B36,MATCH(E4,B5:B36,1))

So the next greater time should simply be

Code:
=INDEX(B5:B36,MATCH(E4,B5:B36,-1))
but I have an unexpected error.
 
Last edited:
Upvote 0
This works with unsorted data in B5:B36
Code:
=SMALL(IF($B$5:$B$36>E4,$B$5:$B$36),1)

This is an array formula, so need CTRL+SHIFT+Enter when you enter it. This should bring {} around it
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

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