VBABEGINER
Well-known Member
- Joined
- Jun 15, 2011
- Messages
- 1,232
Hello Board Members,
I have below code with me. I'm using one command button. After click on 'button', message box appearing and asking user to input date. I want in this code, when this input box appear and suppose user click on cancel or close button, it shall give msg - "You have not entered a date" with error style msg window.
The part which i want to edit highlighted in bold. Pls suggest..
I have below code with me. I'm using one command button. After click on 'button', message box appearing and asking user to input date. I want in this code, when this input box appear and suppose user click on cancel or close button, it shall give msg - "You have not entered a date" with error style msg window.
The part which i want to edit highlighted in bold. Pls suggest..
VBA Code:
Sub Button1_Click()
Dim strDate As String
Dim acceptDate As Integer
Do
Do
strDate = InputBox("Please Enter the DATE as MM/DD/YYYY", "Date", Format(Date - 1, "mm/dd/yyyy"))
[B] If Not IsDate(strDate) Then MsgBox "Please enter a date!", vbCritical
Loop Until IsDate(strDate)[/B]
strDate = Format(CDate(strDate), "mm/dd/yyyy")
acceptDate = MsgBox("The date you entered is " & strDate & vbNewLine & "Accept this date?", vbYesNo)
Loop Until acceptDate = vbYes
Sheets("Sheet1").Range("A3") = strDate
End Sub