Dates in Excel

S

SydneyVada

I am entering past dates in Excel. When I enter a different month & day but
same year in the next row, is there a way to do that without having to enter
the year?
 
G

Gary''s Student

This example is for column D. If you type a month/day in a cell, it will use
the year from the cell above. So if you click on D2 and type 12/25, it gets
the year from D1 and applies it to D2. This is worksheet event code and
should be put in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set d = Range("D:D")
Set d1 = Range("D1")
If Intersect(t, d) Is Nothing Then Exit Sub
If Intersect(t, d1) Is Nothing Then
If IsEmpty(t.Offset(-1, 0)) Then Exit Sub
yr = Year(t.Offset(-1, 0).Value)
Application.EnableEvents = False
v = t.Value
t.Value = DateSerial(yr, Month(v), Day(v))
Application.EnableEvents = True
End If
End Sub
 
S

SydneyVada

Sorry, but that is way above my head. I read up on worksheet event codes,
but I have no idea how or where to put this information.
 

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

Top