我知道这个问题已经得到了完美的回答,但是我只想分享一些代码,这些代码可能会帮助任何正在寻找比“星期四”或“星期二”更强大的东西的人。而是想向函数传递一个日期和日期名称,并取回下一个发生的日期。它是一个两部分功能
Function nextDateofDay(ByVal xdate As Date, ByVal dayOfWeek As String) As
Date
dow = findWeekDayNum(dayOfWeek)
nextDayofWeek = xdate + 7 - Weekday(xdate + 7 - dow)
End Function
Function findWeekDayNum(ByVal dayName As String)
dayName = Trim(UCase(dayName))
daysOfWeek = Array("SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY",
"THURSDAY", "FRIDAY", "SATURDAY")
'Need to find the day of week of that name, so looping through array
For j = LBound(daysOfWeek) To UBound(daysOfWeek)
If daysOfWeek(j) = dayName Then
findWeekDayNum = j + 1 ' need to add one cause array index
'starts at 1
Exit Function
End If
Next j
End Function
然后如何使用一个将简单地使用该功能
sub test()
currentDate = now() ' or can be a date from a cell
dayDesired = "MONDAY" ' or can also be from a cell
nextDate = nextDateofDay(currentDate,dayDesired)
debug.print(nextDate)
end sub