date formatting error

A

Arnold Klapheck

I have users entering info into a worksheet then they click a button to start
the below code. The problem I am having is if they leave it blank I am
getting the format error message instead of the date format error message. I
have the cell formatted as short date I put the cell into a date variable
(mydate) then use mydate in the below code. Even when I put in the date in
correct format I seem to be getting the format error message. Any
help would be appreciated.

If mydate = "" Then
x = MsgBox("blank error message", vbCritical, "Error")
Range("PeriodFrom").Select
Range("PeriodFrom").Activate
End

Exit Sub
Handler:
Select Case Err.Number
Case 13 'data type mismatch
x = MsgBox("Date format error message",
vbCritical, "Error")
Range("PeriodFrom").Select
Range("PeriodFrom").Activate
End
 
S

stevebriz

Arnold,
You are missing a End if and End Select in your code
Try this. It worked for me.
However if it is blank you get your error message then error 1004.
I put in a error handle for error 1004

On Error GoTo Handler
If mydate = "" Then
x = MsgBox("blank error message", vbCritical, "Error")

Range("PeriodFrom").Select
Range("PeriodFrom").Activate
End
End If

Exit Sub
Handler:
Select Case Err.Number
Case 1004
Err.Clear
Case 13 'data type mismatch
x = MsgBox("Date format error message", vbCritical, "Error")
Range("PeriodFrom").Select
Range("PeriodFrom").Activate
End
Case Else

End Select
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top