Date Lookup Return row

hcwest3

New Member
Joined
May 17, 2019
Messages
2
I am in need of vb code that takes date imputed into cell and returns the row number associated with date range.
example below Enter Date of 2/14/2019 and code would return Row number as 3 ( for 2/1/2019 thru 2/28/2019 )


Start DateEnd DateEnter Date:2/14/2019
1/1/20191/31/2019 Row:3
2/1/20192/28/2019
3/1/20193/31/2019
4/1/20194/30/2019

<tbody>
</tbody>

note: I have columns in column A (start date) as namedRange "StateDates"
and columns in B(End Date) as namedRange "EndDates"

any help would be greatly appreciated.

Regards,
Hank West
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
This could easily be converted to a worksheet_change event macro to run automatically whenever a user inputs a date in cell E1.
Code:
Sub GetRow()
Dim Rstart As Range, Rend As Range, D As Date,V As Variant, i As Long, Rw As Long
Set Rstart = Range("StartDates"): Set Rend = Range("EndDates")
Application.ScreenUpdating = False
Rend.Cells(1, 1).Offset(-1, 2).Resize(2, 1).Value = Application.Transpose(Array("Enter Date:", "Row:"))
If Rend.Cells(1, 1).Offset(-1, 3) = "" Or Not IsDate(Rend.Cells(1, 1).Offset(-1, 3)) Then Exit Sub
D = Rend.Cells(1, 1).Offset(-1, 3).Value
V = Range(Rstart, Rend).Value
For i = LBound(V, 1) To UBound(V, 1)
    If D >= V(i, 1) And D <= V(i, 2) Then
        Rw = i + 1
        Rend.Cells(1, 1).Offset(0, 3).Value = Rw
        Exit For
    End If
Next i
If Rw = 0 Then MsgBox "Date entered is not found in search range"
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Joe, thanks for your reply , looks like it should work fine. I will be testing tonight. Rather than a worksheet_change. I will need to convert to a function call where the date to find is passed

xRow = getrow(04/13/2019)

Thanks
Hank
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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