View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default How to write macro for entering mm/yy where it fills to current mm/yy

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Address = "$A$2" Then
On Error GoTo errHandler
Application.EnableEvents = False

If IsDate(Target) Then
i = 0
Do

If Month(Target.Offset(i, 0)) = Month(Date) _
And Year(Target.Offset(i, 0)) = Year(Date) Then
Exit Sub
Else
Target.Offset(i + 1, 0).Value = _
DateSerial(Year(Target.Offset(i, 0)), _
Month(Target.Offset(i, 0)) + 1, 1)
Target.Offset(i + 1, 0).NumberFormat = _
"mm/yy"
i = i + 1
End If
Loop While True
End If
End If
errHandler:
Application.EnableEvents = True
End Sub

Right click on the sheet tab of the sheet where you want this behavior and
select view code.

Paste in code similar to the above.

--
Regards,
Tom Ogilvy

"Annette" wrote in message
...
I would like to be able to enter mm/yy in cell a2, and then run a macro

that
will fill a3 .... to current mm/yy ... how would I write that?

Thanks!

Annette