|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
不知道这样的注释对不对,第一次为了这个代码正儿八经的接触VB,
Public Function chinawork2(startday As Long, wdNum As Integer, Holidays As Range)
Set xD1 = CreateObject("Scripting.Dictionary")
Arr = Holidays
For i = 2 To UBound(Arr)
If Weekday(Arr(i, 1)) = 1 Or Weekday(Arr(i, 1)) = 7 Then
xD1(Arr(i, 1)) = 1
Else
xD1(Arr(i, 1)) = 0
End If
Next i
endday = startday
haha:
'判断是否为周日、周六,1表示为周日、7表示为周六
If Weekday(endday) = 1 Or Weekday(endday) = 7 Then
'如果endday 不在holidays 里面 则 endday=dateadd("d", 1, endday)
If Not xD1.Exists(endday) Then endday = DateAdd("d", 1, endday): GoTo haha
Else
If xD1.Exists(endday) Then endday = DateAdd("d", 1, endday): GoTo haha
End If
'If wdNum = 0 Then chinawork2 = Format(endday, "yyyy-mm-dd"): Exit Function
If wdNum = 0 Then chinawork2 = endday: Exit Function
m = -1
'当 m < abs(wdNum),则
Do While m < Abs(wdNum)
'如果endday 不在holidays 里面 则
If Not xD1.Exists(endday) Then
'如果endday 是周一到周五 则
If Weekday(endday) > 1 And Weekday(endday) < 7 Then
m = m + 1
End If
Else
m = m + xD1(endday)
End If
endday = DateAdd("d", Abs(wdNum) / wdNum, endday)
Loop
endday = DateAdd("d", -Abs(wdNum) / wdNum, endday)
chinawork2 = Format(endday, "yyyy-mm-dd")
'chinawork2 = endday
Set xD1 = Nothing
End Function
|
|