If criteria not met use msgbox

  • Thread starter Thread starter daniels012
  • Start date Start date
D

daniels012

I am very new to code. I have created macros in the past.
How can I write code that would let me manipulate data. For example:
I want them to enter a date that automatically puts Sunday in the cel
above it (Cell C5). I have this done in a formula so far!!
What I want if it's not Sunday, is a message box that pops up and say
"the date you entered is not equal to Sunday, change the date. " The
go back to the cell so they can enter the new date?

I am sure this is basic for some. I just can't get it to work.

Michael;
 
Hi, Michael,
Play with code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$5" Then
If Weekday(Target) <> 1 Then MsgBox "Not Sunday"
End If
End Sub

jeff
 
Maybe you could just use Data|Validation.

Use a custom formula like:

=WEEKDAY(A2)=1

(if A2 held the date)
 

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

Back
Top