Experts Exchange connects you with the people and services you need so you can get back to work.
Private Sub LookupDates()
Dim rngStartDate As Range
Dim rngEndDate As Range
Set rngStartDate = ActiveSheet.Columns(1).Cells
Set rngEndDate = ActiveSheet.Columns(2).Cells
Dim dtCurrent As Date
dtCurrent = Date
' skip the header and trim the range to the last cell with data
Set rngStartDate = ActiveSheet.Range(rngStartDate.Cells(2, 1), rngStartDate.Cells(rngStartDate.Cells.Count).End(xlUp))
Set rngEndDate = rngEndDate.Resize(rngStartDate.Rows.Count, 1).Offset(1, 0)
Dim vBeg As Variant
Dim vEnd As Variant
vBeg = 0
vEnd = 0
Dim i As Long
For i = 1 To rngStartDate.Rows.Count
If (rngStartDate.Cells(i, 1).Value <= dtCurrent) And (rngEndDate.Cells(i, 1).Value >= dtCurrent) Then
vBeg = rngStartDate.Cells(i, 1).Value
vEnd = rngEndDate.Cells(i, 1).Value
If (vBeg > 0) And (vEnd > 0) Then
MsgBox "Found current date between " & vBeg & " and " & vEnd
MsgBox "Did not find date"
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.