If criteria not met use msgbox

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;
 
J

jeff

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
 
D

daniels012

Thank You Jeff!
How do I get it to return to the cell to re-enter the data?


Michae
 
D

Dave Peterson

Maybe you could just use Data|Validation.

Use a custom formula like:

=WEEKDAY(A2)=1

(if A2 held the date)
 
Top