Select Case

K

Ken

Hi Group,
I don't know exactly what I'm doing with this VBA:

Select Case Cells(r, "K").Value
Case Is <> "m&/&d&/&yy"
MsgBox "You have entered an invalid date."

That does not work. What I'm "trying " to do is check a cell that
contains a date to see if it has extraneous characters causing an
invalid date. I'm trying to prevent usiers from mis-typing things into
the cell such as *or ' or // or " for instance. I just can't wrap my
head around a proper way to set it up. I have another Select Case that
checks to see if a cell contains a weekend date, and it works very
well until someone mis-types the aforementioned instances:

Select Case Weekday(Cells(r, "K").Value)
Case 1, 7

MsgBox "You have entered a weekend date." _
& vbLf & "Please enter the date for Friday, or the date
for Monday!"

Cells(r, "K").ClearContents
Case 2, 3, 4, 5, 6
Case Else

If anyone can point me in the right direction, the help will be most
greatly appreciated. Thank so much to the group!
Ken
 
J

Joel

if IsDate(Cells(r, "K").Value ) then

Select Case Weekday(Cells(r, "K").Value)
Case 1, 7

MsgBox "You have entered a weekend date." _
& vbLf & "Please enter the date for Friday, or the date
for Monday!"

Cells(r, "K").ClearContents
Case 2, 3, 4, 5, 6
Case Else
else
MsgBox "You have entered an invalid date."
end if
 

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