MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Macro to ask the user for data.

Posted by Travis on July 25, 2001 12:09 PM

I would like to run a macro that will bring up a data input window asking the user to enter some data (such as a date). Then I will gather information from a spreadsheet that occurred on that date. I just need to know how to ask the user for data.

Posted by Ryan on July 25, 2001 12:31 PM


The easiest way is to do this:

Sub AskForInfo()
Dim Info As Variant

On Error Resume Next
Info = InputBox("Please Enter Date", "Enter Data", "mm/dd/yyyy")
If Info = "" Then Exit Sub
MsgBox "User Entered " & Info

End Sub

HTH, Ryan

Posted by Jerid on July 25, 2001 12:42 PM

Hi Travis

This should do it

Sub GetData()

Dim sUsersData As String
Dim dtDateToSearch As Date

sUsersData = InputBox("Enter the Date" & vbCrLf & "Example (07/25/2001)")
If IsDate(sUsersData) Then
dtDateToSearch = CDate(sUsersData)
'Call your code to search for date, pass it dtDateToSearch
MsgBox "Date not valid"
Exit Sub
End If

End Sub