PDA

View Full Version : Solved: Incorrect Date Brings Up MsgBox



mmwtx
08-20-2009, 09:58 AM
I have created a spreadsheet that we use as an invoice in our office. After a user has completed the invoice, they are to hit a macro button that runs a series of checks on the data entered. One of the common problems was that the user would forget to put a date on the invoice or in some cases, put the wrong date.
So in addition to checking to see if there is something in the field, I want it to check to make sure that the date entered is TODAY and if it's not, to popup with a MSGBOX that says, "Are you sure you want to enter a date other than today?". If they enter yes, the code proceeds with the checking. If they enter No, I want the program to stop running and to go to that field D5 and wait for the user to correct the date.

Being a serious VB newbie, I have been unable to get this to work correctly and would love it if someone could help me! I've searched online and tried various things, but just can't seem to get it! Thank you for any and all help.

Bob Phillips
08-20-2009, 10:47 AM
If Range("D5").Value = "" Then

MsgBox "No date entered"
Range("D5").Select
Exit Sub
ElseIf Range("D5").Value <> Date Then

If MsgBox("Are you sure you want to enter a date other than today?", vbYesNo) = vbNo Then

Range("D5").Select
Exit Sub
End If
End If

'do your stuff

mmwtx
08-20-2009, 12:19 PM
That did it! It was the "ElseIf" command that I didn't have!
Thanks so much for your help!:bow: