![]() |
Dates in Excel
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? -- Self-taught |
Dates in Excel
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 -- Gary''s Student - gsnu200787 "SydneyVada" wrote: 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? -- Self-taught |
Dates in Excel
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. -- Self-taught "Gary''s Student" wrote: 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 -- Gary''s Student - gsnu200787 "SydneyVada" wrote: 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? -- Self-taught |
All times are GMT +1. The time now is 07:01 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com