drpdrpdrp
New Member
- Joined
- Sep 9, 2021
- Messages
- 22
- Office Version
- 2019
- 2016
- Platform
- Windows
I want to return the date components (Year, Month, DayOfYear, DayOfMonth) using a UDF.
Can someone explain why the code below won't work ?
Can someone explain why the code below won't work ?
VBA Code:
Function DateYrMoDoyDom(InputDate As Range)
'makes it easier to extract Year, Month, DayOfYear, DayOfMonth from date
Dim i As Long, rows As Long, r
r = InputDate
rows = UBound(r)
ReDim a(1 To rows, 1 To 4)
For i = 1 To rows
a(i, 1) = Year(r(i, 1))
a(i, 2) = Month(r(i, 1))
a(i, 3) = r(i, 1) - DateSerial(Year(r(i, 1)), 1, 0)
a(i, 4) = Day(r(i, 1))
Next i
DateYrMoDoyDom = a
End Function