Very helpful forum here! Thanks to all who assist!
I'm having trouble coding a Auto Open routine in an Excel sheet ... the objective is:
My code so far is:
I'm stuck I a loop & I haven't figured out the "confirmation yes/no" piece. Please help!
I'm having trouble coding a Auto Open routine in an Excel sheet ... the objective is:
- Upon opening the sheet VBA executes and an input box opens asking the user to input a date
- This date entry is required; so, if the input box is empty or "cancel" is clicked an error is displayed & the code loops back to the original input box asking for the date
- Once the date is entered successfully, the code checks the format of the date & displays a message box showing the date entered.
- In this "confirmation" message box, the user either clicks "Yes" to accept or "No" to start over (which starts the VBA routine over)
- If "Yes" is clicked, the date is placed in a cell on the sheet
My code so far is:
Code:
Sub Auto_Open()
Dim I
For I = 1 To 1 ' Loop 1 time.
Beep ' Sound a tone.
Next I
Dim strDate As String
Dim EntryOK As Boolean
Do While EntryOK > 0
strDate = InputBox("Please Enter the PRODUCTION REPORTING DATE as MM/DD/YYYY", "Production Reporting Date", Format(Now() - 1, "mm/dd/yyyy"))
If IsDate(strDate) = 0 Then 'Checking if Date was entered
MsgBox "Please enter a production date!", vbCritical
Else
If IsDate(strDate) Then
strDate = Format(CDate(strDate), "mm/dd/yyyy")
MsgBox "The PRODUCTION DATE you entered is " & strDate
Else
MsgBox "Wrong Date Format or Missing Date"
End If
End If
Loop
Sheets("DAILY OPERATIONS SUMMARY").Range("e6") = strDate
End Sub
I'm stuck I a loop & I haven't figured out the "confirmation yes/no" piece. Please help!