我有一个从公司电子表格获得的功能来计算撤消日期,我将该工作表作为另一个工作表添加到了工作簿中,以避免在需要使用此功能时打开另一个工作簿。发生的奇怪的事情是该函数正在由我的其他过程执行,而无需我调用该函数。我已经走了很多遍,但不知道为什么要调用此函数。有什么想法吗?
Function sixdayworkweek(rngIn As Range, lngDays As Long, rngHolidays As Range)
Dim rngCell As Range
Dim lngStartDate As Long, lngNextDay As Long, lngWorkDayCount As Long
Dim lngIncr As Long, lngC As Long
Application.Volatile
lngStartDate = CLng(rngIn.Value)
lngNextDay = lngStartDate
Do
lngNextDay = lngNextDay + 1
lngIncr = 1
If Weekday(lngNextDay, vbSunday) = 1 Then
' if day is Sunday, don't count it as a workday
lngIncr = 0
Else
For Each rngCell In rngHolidays
' if day is Holiday, don't count it as a workday
If lngNextDay = CLng(rngCell.Value) Then
lngIncr = 0
Exit For
End If
Next rngCell
End If
' increment day by 1 or 0 if a Sunday or Holiday
lngWorkDayCount = lngWorkDayCount + lngIncr
Loop Until lngWorkDayCount = lngDays
sixdayworkweek = CDate(lngNextDay)
End Function