Input box to find date

T

Tom

Hi,

As part of my macro, how can I make an input box (or whatever box) to
pop up and ask the user to input a date - e.g. 25/06/2097? On
clicking OK, it then goes and locate the date in the spreadsheet.
Thanks for your help.

Tom
 
R

Roger Govier

Hi Tom

Jacob Skaria posted a solution to another query in the programming group
a short while ago.
It should also suit your needs
Sub Macro2()

Dim varDate As Variant, varFound As Variant

varDate = InputBox("Enter Date to be searched")

If IsDate(varDate) Then
Set varFound = Columns(1).Find(CDate(varDate), _
LookIn:=xlValues, Lookat:=xlWhole)
If Not varFound Is Nothing Then
varFound.Activate
Else
MsgBox "Date not found"
End If
Else
MsgBox "Invalid Date"
End If
End Sub

-- Jacob (MVP - Excel)
 
J

Jacob Skaria

Try the below


Sub Macro2()

Dim varDate As Variant, varFound As Variant

varDate = InputBox("Enter Date to be searched")

If IsDate(varDate) Then
Set varFound = Cells.Find(CDate(varDate), _
LookIn:=xlValues, Lookat:=xlWhole)
If Not varFound Is Nothing Then
varFound.Activate
Else
MsgBox "Date not found"
End If
Else
MsgBox "Invalid Date"
End If
End Sub
 
T

Tom

Thanks Roger for pointing that out.

Roger Govier said:
Hi Tom

Jacob Skaria posted a solution to another query in the programming group a
short while ago.
It should also suit your needs
Sub Macro2()

Dim varDate As Variant, varFound As Variant

varDate = InputBox("Enter Date to be searched")

If IsDate(varDate) Then
Set varFound = Columns(1).Find(CDate(varDate), _
LookIn:=xlValues, Lookat:=xlWhole)
If Not varFound Is Nothing Then
varFound.Activate
Else
MsgBox "Date not found"
End If
Else
MsgBox "Invalid Date"
End If
End Sub

-- Jacob (MVP - Excel)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top