Finding a date through an Input Box

SarahB

New Member
Joined
Oct 10, 2002
Messages
2
I want to be able to find a date in a set range as specified through an input box. Dates for some reason seem to cause me a problem - any ideas?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
Hi SarahB,

See if you can modify the following to suit your requirements:

<pre>Sub findit()
Dim FindMe As Date, c As Range, TestArea As Range
Dim firstaddress As String

GetDate:
FindMe = InputBox("Please enter the search date below." & _
vbLf & vbLf & "Use this format DD/MM/YY.", "Date Entry")
If Not IsDate(FindMe) Then
MsgBox "You didn't enter a date!"
GoTo GetDate
End If

Set TestArea = ThisWorkbook.Sheets("Sheet1").Range("A1:A20")

With TestArea
Set c = .Find(What:=FindMe, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not c Is Nothing Then
firstaddress = c.Address
Do
c.Interior.ColorIndex = 4
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstaddress
End If
End With

Set TestArea = Nothing
Set c = Nothing

End Sub</pre>

HTH
 

Forum statistics

Threads
1,143,750
Messages
5,720,633
Members
422,294
Latest member
Gemini774

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
Top