Complicated Match/Lookup in between dates formula?

jwillits

New Member
Joined
Jul 10, 2018
Messages
38
Office Version
  1. 2010
Platform
  1. Windows
Objective: I am trying to obtain a number (ID) from Table A based off of the Date and Number in Table B. What I am trying to say in my formula is that if Phone Number in Table B is equal to a Phone Number in Table A, and the Date in Table B in the same row as that Phone Number is between the Start and End Date in Table A, then I want the corresponding ID from Table A generated in the first column in Table B.

Furthermore, if the phone number matches but it does not fall between a one of the list of dates, I need it to pull the ID from the closest range of dates before it.

For instance, the last row in Table B has a Master Date of 4/22/19, however there is no date range in Table A for it, so it is pulling the ID from the date ranges of 3-26-19 to 4-1-19 because it is the closest date ranges before the master date.

Hopefully this makes sense and there is some wizard out there who can accomplish this. Multiple formulas building on each other is fine as well.





Table A

[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Name[/TD]
[TD]ID[/TD]
[TD]Date Start[/TD]
[TD]Date End[/TD]
[TD]Phone Number[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64"]Apple[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]375[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="class: xl65, width: 108, align: right"]12/30/2018[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 102"]
<tbody>[TR]
[TD="class: xl65, width: 102, align: right"]1/5/2019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 122"]
<tbody>[TR]
[TD="width: 122"]210-908-5231[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]Pear[/TD]
[TD]224[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="class: xl65, width: 108, align: right"]12/30/2018[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 102"]
<tbody>[TR]
[TD="class: xl65, width: 102, align: right"]1/5/2019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 122"]
<tbody>[TR]
[TD="width: 122"]210-361-8442[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]Grape[/TD]
[TD]846[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="class: xl65, width: 108, align: right"]3/26/2019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 102"]
<tbody>[TR]
[TD="class: xl65, width: 102, align: right"]4/1/2019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 122"]
<tbody>[TR]
[TD="width: 122"]210-361-5592[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]Lemon[/TD]
[TD]552[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="class: xl65, width: 108, align: right"]5/26/2019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 102"]
<tbody>[TR]
[TD="class: xl65, width: 102, align: right"]6/1/2019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 122"]
<tbody>[TR]
[TD="width: 122"][TABLE="width: 122"]
<tbody>[TR]
[TD="width: 122"]210-361-5592[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]



Table B

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Master Date[/TD]
[TD]Phone Number[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]224[/TD]
[TD]1/3/19[/TD]
[TD][TABLE="width: 122"]
<tbody>[TR]
[TD="width: 122"]210-361-8442[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]846[/TD]
[TD]3/27/19[/TD]
[TD]210-361-5592[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]846[/TD]
[TD]4/22/19[/TD]
[TD]210-361-5592[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Here is the actual data from my workbook. Note that this info is contained on different pages. In this case, could you write the formula trying to get the Related Weekly Spend number from Sheet2 into the column on Sheet1?

The rules are the same as that I need the Tracking Number to Match from Sheet1 to Sheet2, and then I need the Date in Sheet1 to fall between the Date of the Matching Tracking Number. If there is none, I need it to go to the date range before it.

To continue with the formula, it is important to answer the following:

It is always the previous date.
In an example.
If the date is 25may, the ranges are
a) 1apr - 20apr
b) 26may - 31may
So what is the corresponding range a) or b)?

The nearest date is 26may, but do you want the previous date?

---------------------------------------------

To adapt the formula to rows and columns and sheets, you could upload your file.

You could upload a copy of your file to a free site such www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
To continue with the formula, it is important to answer the following:

It is always the previous date.
In an example.
If the date is 25may, the ranges are
a) 1apr - 20apr
b) 26may - 31may
So what is the corresponding range a) or b)?

The nearest date is 26may, but do you want the previous date?

---------------------------------------------

To adapt the formula to rows and columns and sheets, you could upload your file.

You could upload a copy of your file to a free site such www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.


A would be correct, I need the nearest previous date, only if it is not between a set of dates.
 
Upvote 0
To adapt the formula to rows and columns and sheets, you could upload your file.

You could upload a copy of your file to a free site such www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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