计算新发票日期,包括周末,节假日除外

时间:2010-11-08 15:39:05

标签: excel

我想按如下方式计算新的发票日期:

Starting Date + 14 days 
Where days includes weekends, but excludes holidays.

我该怎么做?

WorkDays和Networkdays功能似乎无法满足我的需求。

3 个答案:

答案 0 :(得分:1)

“假期”的定义因国家,公司,年份等而异,因此没有符合您需求的标准功能。这是我首选方法的过度简化版本:

Function GetNetWorkDays(DateStart As Date, DateEnd As Date) As Integer
    Dim i As Date
    i = DateStart

    While i < DateEnd
        If i <> #01/01/1900# and _
           i <> #01/02/1900# Then _
            GetNetWorkDays = GetNetWorkDays + 1
        i = i + 1
    Wend
    Exit Function
End Function

其中#01/01/1900#和#01/02/1900#是您的首选假期。从长远来看,您希望将日期标准移动到它自己的表格中。

答案 1 :(得分:0)

我知道你需要一个公式的解决方案,而不是VBA。

假设你有:

 A4:A8 -> your holidays table
 A14   -> your start date
 A16   -> number of days to add

生成以下辅助结构:

 c3    -> put a zero
 c4    -> =IF(AND(A4-A$14>0,(A4-A$14)<=(A$16+SUM(C$3:C3))),1,0)
 c5:c8 -> Copy down from c4

因此,要获取新日期,请在结果单元格中键入以下内容:

 =A14+A16+SUM(C4:C8)  

HTH!

答案 2 :(得分:-1)

感谢您的回复。

最后我去了:

Public Function GetCalendarDaysExHolidays(DateStart As Date, MaxDate As Date, NumDays As Integer) As Date
Dim i As Date
Dim DaysCounted As Integer
Dim Rng As Range

DaysCounted = 0

i = DateStart

Do While i < MaxDate

    Set Rng = Sheets("Bank holidays").Range("A1:A1000").Find(what:=Format(DateValue(i), "DD/MM/YYYY"), LookAt:=xlWhole, LookIn:=xlFormulas)
    If Rng Is Nothing Then
        DaysCounted = DaysCounted + 1
    End If

    i = i + 1

    If (DaysCounted = NumDays) Then
        GetCalendarDaysExHolidays = i
        Exit Do
    End If
Loop
Exit Function

结束功能