How to find values that fall between two dates?

Johncapov

New Member
Joined
Mar 2, 2020
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
I have a key of the "Values I'm trying to look up", my "Data" and the date ranges in which they fall.

How would I create a function or VBA tool that will look up the values that match to the "Values I'm trying to look up" along with fall between the two dates?

I'd also like to make the out put comma delimited because multiple values can match from the key based on the date range.

I attempted a INDEX function (I think I am entering the references wrong):

=INDEX($I$3:$I$18,MATCH($I$3:$I$18,K2:L2351,IF(E2>=K$2:K$2351,IF(F2<=K$2:K$2351,IF(Value=K$2:K$2351,1))),0))
I'm a beginner with excel any help would be appreciated.

[enter image description here

I saw this vba on another forum but it does not incorporate the match/vlookup function.

Function SingleCellExtract(LookupValue As String, LookupRange As Range, ColumnNumber As Integer, Char As String)
'Updateby20150824
Dim I As Long
Dim xRet As String
For I = 1 To LookupRange.Columns(1).Cells.Count
If LookupRange.Cells(I, 1) = LookupValue Then
If xRet = "" Then
xRet = LookupRange.Cells(I, ColumnNumber) & Char
Else
xRet = xRet & "" & LookupRange.Cells(I, ColumnNumber) & Char
End If
End If
Next
SingleCellExtract = Left(xRet, Len(xRet) - 1)
End Function
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Show an example of what you would be looking for (search item) and what you would expect to see as an output, and where you want the output to display.
 
Upvote 0
after further review, maybe this is what you want.
Code:
Sub t()
Dim c As Range, fn As Range, r As Range
For Each c In Range("H3", Cells(Rows.Count, "H").End(xlUp))
    Set fn = Range("L:L").Find(c.Value)
        If Not fn Is Nothing Then
            For Each r In Range("E3", Cells(Rows.Count, 5).End(xlUp))
                If fn.Offset(, -1).Value > r.Value And r.Offset(, -1).Value < fn.Offset(, -1).Value Then
                    If r.Offset(, 2) = "" Then
                        r.Offset(, 2) = c.Value
                    Else
                         r.Offset(, 2) = r.Offset(, 2).Value & ", " & c.Value
                    End If
                End If
            Next
        End If
Next
End Sub
 
Upvote 0
Hi, Thank you very much for the response. I apologize for the delayed reply (was out of office).

I will try this script you created, but what I'm trying to obtain is the codes that fall in column L that falls between the date range found in column E and F and only the ones that match to the code key I2:I18. The output would go in column G hopefully separated by commas depending on how many codes appear.

Hopefully that made it make more sense.
 
Upvote 0
That is what the code I posted is supposed to do, and it tested OK in a mock up.
 
Upvote 0
My test file looked like your example in the OP, except I inadvertantly used Column H instead of Column I for the search items. The code below has been modified to use column I.

Code:
Sub t()
Dim c As Range, fn As Range, r As Range
For Each c In Range("I3", Cells(Rows.Count, "I").End(xlUp))
    Set fn = Range("L:L").Find(c.Value)
        If Not fn Is Nothing Then
            For Each r In Range("E3", Cells(Rows.Count, 5).End(xlUp))
                If fn.Offset(, -1).Value > r.Value And r.Offset(, -1).Value < fn.Offset(, -1).Value Then
                    If r.Offset(, 2) = "" Then
                        r.Offset(, 2) = c.Value
                    Else
                         r.Offset(, 2) = r.Offset(, 2).Value & ", " & c.Value
                    End If
                End If
            Next
        End If
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,422
Messages
6,190,959
Members
453,626
Latest member
Paneru

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