Formula help please

DrH100

Board Regular
Joined
Dec 30, 2011
Messages
78
In a spreadsheet I have a column of dates (column r).

I have a formula in a cell

=INDEX($R$4:$R$57, MATCH(MIN(ABS($R$4:$R$57-$H$7)), ABS($R$4:$R$57-$H$7), 0))

Which is looking for the nearest date in column r (my list) to the date in H7. This has been working fine but I now need to tweak it a bit to look for the nearest date, but not past the date in H7.

I'm not sure which bit of this formula I should tweak - or if indeed it can be tweaked to do this.

I thought about something like

=INDEX(R4:R57, MATCH(MIN(IF(R4:R57-$H$7<=0, R4:R57-$H$7, "")), R4:R57-$H$7, 0))

but this just returns the first entry in R4 everytime no mater what the date in h7

As always any help appreciated.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I have not actually tried this but don't you just need to lose the two ABS functions. They are what is causing a date close to H7 to count no matter which side it is on.
 
Upvote 0
Thanks RickXL

I must admit I tried taking the ABS functions out but that just takes it to the first entry in the list no matter what date is put in my cell H7.

Thanks for the reply though.

David
 
Upvote 0
Control+shift+enter, not just enter:
Rich (BB code):
=INDEX($R$4:$R$57, MATCH(MIN(IF($R$4:$R$57>$H$7,9.99999999999999E+307,ABS($R$4:$R$57-$H$7))), 
   ABS($R$4:$R$57-$H$7), 0))
 
Upvote 0
Maybe something like this...

=MAX(IF(H7>=R4:R57,R4:R57))

Ctrl+Shift+Enter, not just Enter

M.
 
Upvote 0
It's a good puzzle, David :)

This seems to work:
=$H$7+MAX(IF(($R$4:$R$57-$H$7)<=0,($R$4:$R$57-$H$7),-999999))

and this:
=$H$7+MAX(IF(($R$4:$R$57-$H$7)<=0,($R$4:$R$57-$H$7)))

So does this:
=INDEX(SMALL($R$4:$R$57,ROW(R$4:$R$57)-3),MATCH($H$7,SMALL($R$4:$R$57,ROW($R$4:$R$57)-3),1))

Both need Ctrl + Shift + Enter.

The problem becomes easier if the list of dates is in order.
 
Last edited:
Upvote 0
It's a good puzzle, David :)

This seems to work:
=$H$7+MAX(IF(($R$4:$R$57-$H$7)<=0,($R$4:$R$57-$H$7),-999999))

and this:
=$H$7+MAX(IF(($R$4:$R$57-$H$7)<=0,($R$4:$R$57-$H$7)))

So does this:
=INDEX(SMALL($R$4:$R$57,ROW(R$4:$R$57)-3),MATCH($H$7,SMALL($R$4:$R$57,ROW($R$4:$R$57)-3),1))

Both need Ctrl + Shift + Enter.

The problem becomes easier if the list of dates is in order.

I think my formula in #8 is simpler

=MAX(IF(H7>=R4:R57,R4:R57))

Ctrl+Shift+Enter

M.
 
Upvote 0
Marcelo,

I tried your formula and it didn't work.

Now I have rebooted my brain and go my act into gear I see that it does, in fact work very well.

I salute your conciseness :)

Rick
 
Upvote 0
Marcelo,

I tried your formula and it didn't work.

Now I have rebooted my brain and go my act into gear I see that it does, in fact work very well.

I salute your conciseness :)

Rick

Rick,

Thank you for your kind words.

(y)

M.
 
Upvote 0

Forum statistics

Threads
1,216,797
Messages
6,132,747
Members
449,757
Latest member
budha465

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