Starting Date of the Month
Jerry,
Try this
Private Sub Worksheet_Change(ByVal Target As Range)
If (Target.Column = 1) Then
If (IsDate(Target.Text)) Then
Target = (CStr(Month(Target.Text)) + "-01-" + _
CStr(Year(Target.Text)))
End If
msgbox "Date was changed"
End If
End Sub
It might give you some indication why Ron has put in
Application.EnableEvents = False
at the top of his code and reenabled them at the bottom.
--
Regards,
Tom Ogilvy
"Jerry Park" wrote in message
...
Soniya wrote:
Hi all,
How can I change the date of a given cell to be the first day of that
month?
for eg. if I enter in A1 16-2-2002 I want to get 01-2- 2002 in the
same cell
if I use =DATE(YEAR($A$1),MONTH($A$1),1) in my B1 i will get the
first day of the date entered in A1. but i want to get it in A1
itself using code?
Any help?
TIA Soniya
Sounds like you need to use the onchange event:
Private Sub Worksheet_Change(ByVal Target As Range)
If (Target.Column = 1) Then
If (IsDate(Target.Text)) Then
Target = (CStr(Month(Target.Text)) + "-01-" +
CStr(Year(Target.Text)))
End If
End If
End Sub
Note: My email client insists on wrapping the assignment line.
|