vba convert week number (and year) to date?

后端 未结 3 556
渐次进展
渐次进展 2021-01-05 01:00

I have a week number in Cell C13 and a year in Cell C14.

I am using the below formula to convert this into the Thursday of

3条回答
  •  执念已碎
    2021-01-05 01:44

    It works quite ok, taking in mind that the first day of the week is Sunday:

    Function fnDateFromWeek(ByVal iYear As Integer, ByVal iWeek As Integer, ByVal iWeekDday As Integer)
    
            fnDateFromWeek = DateSerial(iYear, 1, ((iWeek - 1) * 7) + iWeekDday - Weekday(DateSerial(iYear, 1, 1)) + 1)
    
    End Function
    

    You have to pass which day do you want as third parameter. Thursday is day number 5. Credits to these guys: http://www.dreamincode.net/forums/topic/111464-calculate-date-from-year-weeknr-and-daynumber/

提交回复
热议问题