Code:Private Sub Workbook_Open() Dim vDate As Variant While Not IsDate(vDate) vDate = InputBox("Whats my Begin Date", "Begin Date Input", Format(Now(), "dd/mm/yyyy")) If vDate = "" Then '' they presed cancel Exit Sub 'exit doing nothing End If If IsDate(vDate) Then Sheet1.Range("g1").Value = vDate '' a good date has been entered Exit Sub Else MsgBox "No Valid Begin Date entered" End If Wend End Sub [code][/QUOTE] Wow, unbelievable, thank you so much!!! It helps me so much. I really appreciate your help guys!!!
Code:Private Sub Workbook_Open() Dim vDate As Variant While Not IsDate(vDate) vDate = InputBox("Whats my Begin Date", "Begin Date Input", Format(Now(), "dd/mm/yyyy")) If vDate = "" Then '' they presed cancel Exit Sub 'exit doing nothing End If If IsDate(vDate) Then Sheet1.Range("g1").Value = vDate '' a good date has been entered Exit Sub Else MsgBox "No Valid Begin Date entered" End If Wend End Sub
One last question, is there also a possibility to build in an End date? The end date should be put on cell J1. Should this be a separate macro, or is it possible to build 1 macro for both dates, such that it first asks for Begin date and after that asking for the End date?
Once again thanks in advance.
2 conditions
Suprisingly Now You have to specify what will happen
Start date cancelled, should workvbook ask about an end date?
Is valid start date plus valid end date only
or can it be start date :- a date is entered, end date is cancelled
HOW DO YOU SEE IT WORKING KNOWING HOW IMPERFECT PEOPLE ARE?
Private Sub Workbook_Open()
Dim dt1 As Long, dt2 As Long, dtcheck As Boolean
line2:
On Error GoTo line1
If Not dtcheck Then dt1 = DateValue(InputBox("What is your start date?"))
dtcheck = 1
dt2 = DateValue(InputBox("What is your finish date?"))
If dt2 < dt1 Then
MsgBox "Must be after Start date, please try again", vbOKOnly
GoTo line2
End If
On Error GoTo 0
Sheet1.Range("G1") = dt1
Sheet1.Range("J1") = dt2
Exit Sub
line1:
MsgBox "Not a valid date Please try again", vbOKOnly
Resume line2
End Sub
line1:
If MsgBox("Not a valid date Please try again", vbAbortRetryIgnore) = vbAbort Then ThisWorkbook.Close
Resume line2
can the dates be the same? can start date be after end date?? all of things a user does
Charles, thanks, this was exactly what I was looking for. The date conditions are also OK, no need to change anything, if the user still succeeds to get the wrong data, then we should doubt the brain of the user!!!!