PDA

View Full Version : Solved: lookup date



av8tordude
10-07-2011, 05:46 PM
Can someone assist with a code that will look in column B (Range B11:B250) and determine if a date exist. If so, go to that cell with requested date. If not, then exit sub.

Thank you for your assistance.

GTO
10-07-2011, 10:03 PM
Maybe:
Option Explicit

Sub exa()
Dim ret As String
Dim arySplit() As String
Dim rng As Range
Dim dtmLookFor As Date

ret = Application.InputBox( _
"Enter the date in the following format: m,d,yyyy" & vbCrLf & _
"That is, a one or two digit number for the month, followed by a comma," & _
" followed by a one or two digit number for the day, followed by a comma," & _
" followed by a four digit number for the year.", "Enter Date", , , , , , 2)

If InStr(1, ret, ",") Then
arySplit = Split(ret, ",")
If UBound(arySplit) = 2 Then
dtmLookFor = DateSerial(Trim(arySplit(2)), _
Trim(arySplit(0)), _
Trim(arySplit(1)))
Set rng = Range("B11:B250").Find(dtmLookFor, Range("B250"), xlFormulas, xlWhole)
If Not rng Is Nothing Then
Application.Goto rng, True
End If
End If
End If
End Sub

av8tordude
10-07-2011, 11:01 PM
thank you GTO

GTO
10-08-2011, 07:03 AM
You are most welcome :-)