Lookup name, then date within dates

Donager

New Member
Joined
Mar 28, 2015
Messages
17
I tried to search for this and was unable to find it. If someone knows of an existing thread, please link me to it as I don't wish to recreate the wheel.

I am trying to create a formula that takes the name in table 1 and looks it up in table 2. If it finds that name, it should look up the coinciding date in table 1 to determine if it is between the start and end date in table 2.

I have tried several nested if statements combined with vlookup, index match and such and not gotten anywhere.

I would appreciate any assistance. Once I figure the look up, I can combine it with my other formulas.

Table 1
NameDate
Bob1/19/2018
Bill2/20/2018
Fred1/15/2018
Gus1/12/2018

<tbody>
</tbody>


Table 2
NameStartEnd
Bob1/1/20182/1/2018
Fred12/1/20173/20/2018
Shirly1/1/20181/15/2018
Suzy2/1/20182/25/2018

<tbody>
</tbody>
 

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.
How about?

ABC
1Table 1
2NameDate
3Bob1/19/2018Yes
4Bill2/20/2018No
5Fred1/15/2018Yes
6Gus1/12/2018No
7
8
9
10Table 2
11NameStartEnd
12Bob1/1/20182/1/2018
13Fred12/1/20173/20/2018
14Shirly1/1/20181/15/2018
15Suzy2/1/20182/25/2018

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet3

Worksheet Formulas
CellFormula
C3=IF(COUNTIFS($A$12:$A$15,A3,$B$12:$B$15,"<="&B3,$C$12:$C$15,">="&B3),"Yes","No")

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
Here is a VBA solution. Assume table1 and table2 are sheet names. This determines first if the name is in table2 and then determines if the date is within the date range.

Code:
Option Explicit


Sub FindBetween()
    Dim s1 As Worksheet, s2 As Worksheet
    Set s1 = Sheets("Table1")
    Set s2 = Sheets("Table2")
    Dim i As Long, lr1 As Long, lr2 As Long
    Dim j As Long
    lr1 = s1.Range("A" & Rows.Count).End(xlUp).Row
    lr2 = s2.Range("A" & Rows.Count).End(xlUp).Row
    Dim res As Variant
    For i = 2 To lr1
        Dim found As Range
        Set found = Sheets("Table2").Columns("A").Find(what:=s1.Range("A" & i), LookIn:=xlValues, lookat:=xlWhole)
        If Not found Is Nothing Then
            s1.Range("C" & i) = "Found"
            j = found.Row
            If s1.Range("B" & i) > s2.Range("B" & j) And s1.Range("B" & i) < s2.Range("C" & j) Then
                s1.Range("D" & i) = "Within Date Span"
            End If
        End If
    Next i
End Sub
 
Last edited:
Upvote 0
Here is a VBA solution. Assume table1 and table2 are sheet names. This determines first if the name is in table2 and then determines if the date is within the date range.

Code:
Option Explicit


Sub FindBetween()
    Dim s1 As Worksheet, s2 As Worksheet
    Set s1 = Sheets("Table1")
    Set s2 = Sheets("Table2")
    Dim i As Long, lr1 As Long, lr2 As Long
    Dim j As Long
    lr1 = s1.Range("A" & Rows.Count).End(xlUp).Row
    lr2 = s2.Range("A" & Rows.Count).End(xlUp).Row
    Dim res As Variant
    For i = 2 To lr1
        Dim found As Range
        Set found = Sheets("Table2").Columns("A").Find(what:=s1.Range("A" & i), LookIn:=xlValues, lookat:=xlWhole)
        If Not found Is Nothing Then
            s1.Range("C" & i) = "Found"
            j = found.Row
            If s1.Range("B" & i) > s2.Range("B" & j) And s1.Range("B" & i) < s2.Range("C" & j) Then
                s1.Range("D" & i) = "Within Date Span"
            End If
        End If
    Next i
End Sub



Thank you, alansidman. I intend to work on my VBA scripting and this is a real-world application VBA I can use for reference.
 
Upvote 0

Forum statistics

Threads
1,215,084
Messages
6,123,029
Members
449,092
Latest member
ikke

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