Find the Closest Date to Today

Nanogirl21

Active Member
Joined
Nov 19, 2013
Messages
330
Office Version
  1. 365
Platform
  1. Windows
How can I search similar to vlookup to return the matching date that is nearest to today? The search term will have multiple matches, but I only want to return the nearest date. A future or current date is always preferred, but if not available the nearest past date is acceptable.

Example:
Apple1/5/2022
Grape7/7/2022
Apple4/2/2022
Pear5/2/2022
Apple1/11/2022
Apple5/2/5000

Search: Apple
Today Date: 2/8/2022
Expected Result: 4/2/2022

Thank you.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
i use european dateformat dd/mm/yy, so the formula is okay for both dateformats, but the result here are okay in my eyes.
Use that formula with all mm/dd/yy-dates and the result 'll also be okay.
Map1
ABCDEF
1Apple1/05/20225/02/22nearest in future and past
2Grape7/07/20221/05/22nearest in future
3Apple4/02/2022
4Pear5/02/2022
5Apple1/11/2022
6Apple5/02/5000
Blad1
Cell Formulas
RangeFormula
D1D1=INDEX(B1:B6,MATCH(MIN(ABS(B1:B6-TODAY())),ABS(B1:B6-TODAY()),0))
D2D2=INDEX(B1:B6,MATCH(MIN(IF(B1:B6>=TODAY(),B1:B6-TODAY(),"")),IF(B1:B6>=TODAY(),B1:B6-TODAY(),""),0))
 
Upvote 0
=INDEX(B1:B6,MATCH(MIN(IF(B1:B6>=TODAY(),B1:B6-TODAY(),"")),IF(B1:B6>=TODAY(),B1:B6-TODAY(),""),0))

Thank you. How do I identify which keyword the formula is looking for? I am looking to only find the date that matches the word Apple, not the entire range.
 
Upvote 0
How about
+Fluff 1.xlsm
ABCDE
1
2Apple05/01/2022Apple02/04/2022
3Grape07/07/2022Pear01/01/2022
4Apple02/04/2022
5Pear02/05/2021
6Apple11/01/2022
7Apple02/05/5000
8Pear01/01/2022
9
Primary
Cell Formulas
RangeFormula
E2:E3E2=LET(f,FILTER($B$2:$B$100,$A$2:$A$100=D2),XLOOKUP(TODAY(),f,f,XLOOKUP(TODAY(),f,f,,-1),1))
 
Upvote 0
Solution
How about
+Fluff 1.xlsm
ABCDE
1
2Apple05/01/2022Apple02/04/2022
3Grape07/07/2022Pear01/01/2022
4Apple02/04/2022
5Pear02/05/2021
6Apple11/01/2022
7Apple02/05/5000
8Pear01/01/2022
9
Primary
Cell Formulas
RangeFormula
E2:E3E2=LET(f,FILTER($B$2:$B$100,$A$2:$A$100=D2),XLOOKUP(TODAY(),f,f,XLOOKUP(TODAY(),f,f,,-1),1))

This worked. Thank you.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
How about
+Fluff 1.xlsm
ABCDE
1
2Apple05/01/2022Apple02/04/2022
3Grape07/07/2022Pear01/01/2022
4Apple02/04/2022
5Pear02/05/2021
6Apple11/01/2022
7Apple02/05/5000
8Pear01/01/2022
9
Primary
Cell Formulas
RangeFormula
E2:E3E2=LET(f,FILTER($B$2:$B$100,$A$2:$A$100=D2),XLOOKUP(TODAY(),f,f,XLOOKUP(TODAY(),f,f,,-1),1))

HI, I've been playing around with your solution and am running into a problem.

Currently, the formula is matching and pulling the first date in the series that is a match. It is not matching the date that is nearest to today's date. How can I adjust the formula?

Example:
2/14/2019
4/2/2022
4/1/2026

The formula is returning 2/14/2019 as the result. If I sort the data it will then show 4/1/2026 as the result. However, the closest to today (02/15/2022) is 4/2/2022. I am expecting 4/2/2022 as the answer.
 
Upvote 0
That's the answer I get.
+Fluff 1.xlsm
ABCDE
1
2Apple14/02/2019Apple02/04/2022
3Grape07/07/2022Pear01/01/2022
4Apple02/04/2022
5Pear02/05/2021
6Apple02/04/2022
7Apple01/04/2026
8Pear01/01/2022
9
Main
Cell Formulas
RangeFormula
E2:E3E2=LET(f,FILTER($B$2:$B$100,$A$2:$A$100=D2),XLOOKUP(TODAY(),f,f,XLOOKUP(TODAY(),f,f,,-1),1))


Check that your dates are not text
 
Upvote 0

Forum statistics

Threads
1,214,845
Messages
6,121,902
Members
449,053
Latest member
Guy Boot

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