要求:
计算日期范围之间的节假日星期一的数量,并使用宏执行它们。
我可以得出他的公式可以给我正确的结果
=SumProduct((VIC >= DATEVALUE("1/01/2016")) * (VIC <= DATEVALUE("19/01''/2018")) * (Weekday(VIC, 2) = 1))
您能帮我执行存储在字符串中的公式吗?
Sub TestFunction()
Dim LeaveStartDate, LeaveEndDate As Date
Set srcdoc = Worksheets("Sheet1")
Dim CntSunPH As String
LeaveStartDate = Worksheets("Sheet1").Cells(1, "B").Value
LeaveEndDate = Worksheets("Sheet1").Cells(2, "B").Value
State = "VIC"
CntSunPH = Replace((Replace(Replace(("=SumProduct((State >= DATEVALUE(""LeaveStartDate"")) * (State <= DATEVALUE(""LeaveEndDate"")) * (Weekday(State, 2) = 1))"), "State", State), "LeaveStartDate", LeaveStartDate)), "LeaveEndDate", LeaveEndDate)
n = 0
n = Application.WorksheetFunction.Execute("=SumProduct((VIC >= DATEVALUE(""1/01/2016"")) * (VIC <= DATEVALUE(""19/01/2018"")) * (Weekday(VIC, 2) = 1))")
Debug.Print "Date1 " & LeaveStartDate
Debug.Print "Date2 " & LeaveEndDate
Debug.Print CntSunPH
Debug.Print n
End Sub