View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chris Chris is offline
external usenet poster
 
Posts: 244
Default If criteria not met then message box

Put this in your Worksheet change event
Make changes asif needed as noted next to code

Private Sub Worksheet_Change(ByVal Target As Range
On Error Resume Nex

If Target.Cells.Count = 1 And
Not IsEmpty(Target) And
Target.Address = "$C$6" Then '<< Assumes this is your entry cel

If Not IsDate(Target) The
MsgBox "Must be a Valid Date!
Target.Value = "
Exit Su
End I

If Weekday(CDate(Target.Value)) < 1 The
MsgBox "Must be a Valid Sunday Date!
Target.Value = "
Exit Su
End I

'Use this if you need to check that date is not a Future dat
'If CDate(Target.Value) Now The
'MsgBox "Can Not be a Future date!
'Use this if you need to check that date is not a Past dat
'If CDate(Target.Value) < Now The
'MsgBox "Can Not be a Past date!

'Target.Value = "
'Exit Su
'End I

End I
End Su

----- daniels012 wrote: ----

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


--
Message posted from http://www.ExcelForum.com