snakehips2000
Programmer
I picked up the following two functions as a means of determining a date from a week number in Excel VBA. Unfortunately, when used together, they return the same date for both week 53 of 2010 and week 1 of 2011 (3 Jan).
Does anyone have anything more reliable please?
Thanks.
Does anyone have anything more reliable please?
Thanks.
Code:
Public Function YearStart(WhichYear As Integer) As Date
Dim WeekDay As Integer
Dim NewYear As Date
NewYear = DateSerial(WhichYear, 1, 1)
WeekDay = (NewYear - 2) Mod 7 'Generate weekday index where Monday = 0
If WeekDay < 4 Then
YearStart = NewYear - WeekDay
Else
YearStart = NewYear - WeekDay + 7
End If
End Function
Public Function WeekStart(WhichWeek As Integer, WhichYear As _
Integer) As Date
WeekStart = YearStart(WhichYear) + ((WhichWeek) * 7)
End Function