Получить дату из номера недели
'================================================================================================
'##### Дата по номеру недели
'Sub test_Fn_DateInWeekNum()
' d = Fn_DateInWeekNum(2018, 26, 7)
'End Sub
'------------------------------------------------------------------------------------------------
Function Fn_DateInWeekNum(ByVal intYear As Integer, _
ByVal intWeek As Integer, _
ByVal intDay As Integer) As Date
'Dim intYear As Integer: intYear = Year(Now)
'Dim intWeek As Integer: intWeek = 27 'номер недели
'vbMonday = 2 (Понедельник)
Dim intYearStart As Integer
intYearStart = Format("01.01." & intYear, "w", vbMonday)
If intDay = 0 Then
Fn_DateInWeekNum = DateSerial(intYear, 1, 7 * intWeek - intYearStart - 5)
Else
Fn_DateInWeekNum = DateSerial(intYear, 1, 7 * intWeek - intYearStart - 5) + intDay - 1
End If
End Function
'================================================================================================
'http://bbs.vbstreets.ru/viewtopic.php?p=6679215#
Sub дата_по_номеру_недели()
Dim intYear As Integer: intYear = Year(Now)
Dim intYearStart As Integer
Dim intWeek As Integer: intWeek = 27 'номер недели
'vbMonday = 2 (Понедельник)
intYearStart = Format("01.01." & intYear, "w", vbMonday)
Debug.Print DateSerial(intYear, 1, 7 * intWeek - intYearStart - 5)
End Sub
Sub дата_по_номеру_недели2()
Ned = 26
FstDay = "01.01." & Year(Now) 'DateSerial(Year(Now), 1, 1)
FstNedStart = DateAdd("d", -Weekday(FstDay, vbMonday) + 1, FstDay)
NedStart = DateAdd("d", (Ned - 1) * 7, FstNedStart)
NedEnd = DateAdd("d", (Ned - 1) * 7 + 6, FstNedStart)
End Sub
'http://forum.sources.ru/index.php?showtopic=292216
'DateSerial(year,1,1) даст 1 января нужного года. _
К нему надо прибавить (DateAdd) нужное количество недель, а потом отнять (DatesSub) количество дней, _
равных коду номера дня. Всё.
Sub дата_по_номеру_недели3()
iYear = 2018
iWeekNum = 26
iDate = DateSerial(iYear, 1, 1) - Weekday(DateSerial(iYear, 1, 1), vbTuesday) + (iWeekNum) * 7
End Sub