loop though dates column and if matched get value from the next column

nikolay100

New Member
Joined
Oct 14, 2022
Messages
6
Office Version
  1. 2021
Platform
  1. Windows
Hi everyone,

So I have the following table:
Date1
Currency
Date2
2023-02-01​
1.79533
2023-03-22​
2023-02-02​
1.77997
2023-03-04​
2023-02-03​
1.78827
2023-03-25​
2023-02-06​
1.81499
2023-03-22​
2023-02-07​
1.82788
2023-03-22​
2023-02-08​
1.82192
2023-03-18​
2023-02-09​
1.81583
2023-03-22​
2023-02-10​
1.82959
2023-03-22​
2023-02-13​
1.83027
2023-03-12​
2023-02-14​
1.81785
2023-03-22​
2023-02-15​
1.82788
2023-02-16​
1.82788
2023-02-17​
1.84078
2023-02-20​
1.83233
2023-02-21​
1.83405
2023-02-22​
1.8375
2023-02-23​
1.84234
2023-02-24​
1.85036
2023-02-27​
1.85316
2023-02-28​
1.84182

The idea is to compare each cell from Date2 column with each cell from Date1 column and if there is a match to get the value from the currency column. And then there is a the tricky part, if there is no match it should pick the the closest date in the past from this range.

For example:
In case of the first row cell in Date2 - 2023-03-22, since there is a match it should select 1.8375.
In case of the second row cell in Date2 - 2023-03-04, there is no match and it should select the value from 2023-02-03, which is 1.78827

Is this achievable with a regular formula? If not then, what would be the best solution for this?

Thanks in advance.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Apologies I used the wrong examples. Here is the correct data:
Date1
Currency
Date2
2023-02-011.795332023-02-22
2023-02-021.779972023-02-04
2023-02-031.788272023-02-25
2023-02-061.814992023-02-22
2023-02-071.827882023-02-22
2023-02-081.821922023-02-18
2023-02-091.815832023-02-22
2023-02-101.829592023-02-22
2023-02-131.830272023-02-12
2023-02-141.817852023-02-22
2023-02-151.82788
2023-02-161.82788
2023-02-171.84078
2023-02-201.83233
2023-02-211.83405
2023-02-221.8375
2023-02-231.84234
2023-02-241.85036
2023-02-271.85316
2023-02-281.84182

The idea is to compare each cell from Date2 column with each cell from Date1 column and if there is a match to get the value from the currency column. And then there is a the tricky part, if there is no match it should pick the closest date in the past from this range.

For example:
In case of the first row cell in Date2 - 2023-02-22, since there is a match it should select 1.8375.
In case of the second row cell in Date2 - 2023-02-04, there is no match and it should select the value from 2023-02-03, which is 1.78827
 
Upvote 0
Consider the example below.
N.B. It is much better to post with the forum's tool named XL2BB. I converted the text to dates.

T202303a.xlsm
ABCDE
1Date1CurrencyDate2
21-Feb-231.7953322-Feb-231.8375
32-Feb-231.779974-Feb-231.78827
43-Feb-231.78827
56-Feb-231.81499
67-Feb-231.82788
78-Feb-231.82192
89-Feb-231.81583
910-Feb-231.82959
1013-Feb-231.83027
1114-Feb-231.81785
1215-Feb-231.82788
1316-Feb-231.82788
1417-Feb-231.84078
1520-Feb-231.83233
1621-Feb-231.83405
1722-Feb-231.8375
1823-Feb-231.84234
1924-Feb-231.85036
2027-Feb-231.85316
2128-Feb-231.84182
5a
Cell Formulas
RangeFormula
E2:E3E2=LOOKUP(D2,$A$2:$B$21)
 
Last edited:
Upvote 1
Solution

Forum statistics

Threads
1,215,528
Messages
6,125,342
Members
449,218
Latest member
Excel Master

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