我正试图找到一种方法来找到日期值,给定WEEKNUM和WEEKDAY
例如
WEEKNUM = 9
WEEKDAY = 4 '(Wednesday)
我可以使用以下功能从日期中找到WEEKNUM,但我怎么能走另一条路呢?
Function WEEKNUM(D As Date, FW As Integer) As Integer
WEEKNUM = CInt(Format(D, "ww", FW))
End Function
答案 0 :(得分:1)
您可以在隐藏工作表上使用表格,并使用Vlookup查找正确的日期。 EG
DATE WEEKDAY WEEK NO WEEKDAY + WEEK NO
01/03/2016 Tuesday Week 10 Tuesday 10
02/03/2016 Wednesday Week 10 Wednesday 10
在VBA中,您可以查找工作表的名称,即工作日,并从工作簿的文件名中获取周数,然后使用vlookup查找正确的日期。
weekNum = Mid(ThisWorkbook.Name, 6, 2)
searchStr = ActiveSheet.Name & " " & weekNum & " " & Format(Now(), "YYYY")
rowNo = Application.WorksheetFunction.Match(searchStr, Sheets("WEEKLIST").Range("D:D"), 0)
strSubject = Format(Sheets("WEEKLIST").Range("A" & rowNo).Value, "DD/MM")