Основная функция, вызывающая Day1WeekNum & Day1inMonth
Function NthDay(Date1)
' Tells you if a date is the 3rd Tuesday of the Month
Dim Day1Name, Day1WeekNum, A, B, DayName, Nth
Dim Status ' Tells you if there is anything in the rest of the Array
Dim cWeekNum ' Number for the current week
Dim WeekDiff 'Difference between the week numbers
Dim cDayNum 'Number for the day of the week for Date1
Dim Week1Num
Week1Num = Day1WeekNum(Date1) ' tells me the week number of the first day of the month
Day1Name = Day1inMonth(Date1) ' tell me the day of the week for the first day of the month
Код для Day1inMonth
Function Day1inMonth(Date1)
'Tells you the weekday of the first day in a month of the provided date
Dim cYear, cMonth, month1st, day1
cYear = Year(Date1)
cMonth = Month(Date1)
month1st = DateSerial(cYear, cMonth, 1)
day1 = Weekday(month1st, vbSunday)
Day1inMonth = day1
End Function
Код для Day1WeekNum
Function Day1WeekNum(Date1 As Date)
'Tells you the week of the first day of the month of the provided date
Dim cYear, cMonth, day1Week
Dim month1st As Date
cYear = Year(Date1)
cMonth = Month(Date1)
month1st = DateSerial(cYear, cMonth, 1)
day1Week = WorksheetFunction.WeekNum(month1st, 1)
Day1WeekNum = day1Week
End Function
Мне пришлось изменить код вышек коду ниже, чтобы остановить ошибку несоответствия. Я не знаю почему. Это должно относиться к переменной области или что-то еще? Я пытаюсь понять, чтобы избежать причины ошибки в будущем.
Новый код, который позволил ему работать:
Function Day2WeekNum(Date1)
'Tells you the week of the first day of the month of the provided date
Dim cYear1, cMonth1, day1Week1
Dim month1st1 As Date
cYear1 = Year(Date1)
cMonth1 = Month(Date1)
month1st1 = DateSerial(cYear, cMonth, 1)
day1Week1 = WorksheetFunction.WeekNum(month1st, 1)
Day2WeekNum = day1Week1
End Function