写了一个function,然后我在单元格里写了=work(202301,2022/2/21,""),结果显示VALUE,帮忙看下是哪里有问题。
代码如下:
Function work(a As Long, b As Date, c As Date)
Dim x As Range, y As Range
Dim d, e
x = Sheets(节假日).Range("B2:B51")
y = Sheets(节假日).Range("A2:A1000")
If DatePart(Left(a, 4), Right(a, 2), 1) > b Then
d = DatePart(Left(a, 4), Right(a, 2), 1)
Else: d = b
End If
If DatePart(Left(a, 4), Right(a, 2) + 1, 1) - 1 < c Then
e = DatePart(Left(a, 4), Right(a, 2) + 1, 1) - 1
Else: e = c
End If
If c = "" Or c > DatePart(Left(a, 4), Right(a, 2), 1) Then
工作日 = NetworkDays.INTL(d, e, 1, x) + Application.WorksheetFunction.CountIfs(y, "<=" & DatePart(Left(a, 4), Right(a, 2) + 1, 1) - 1, y, ">=" & DatePart(Left(a, 4), Right(a, 2), 1))
Else: 工作日 = 0
End If
End Function
|