你要去,如果你可以輸入你的票開放時間爲日期會更好,然後用VBA函數計算到期日。然後,您可以計算機票關閉日期並進行比較,或計算時間差異並進行比較。假設你實際上並不需要每月的一天,因爲你只關心一週中的某一天,但最好包括如下所示的月份中的一天。
編輯 的VBA函數下面可以通過在工作表公式來實現同樣的功能:
=IF(WORKDAY(WORKDAY(H2,1,Holidays),-1,Holidays) = ROUNDDOWN(H2,0), WORKDAY(H2,IF(HOUR(H2)>=18,2,1),Holidays)+18/24, WORKDAY(WORKDAY(H2,-1,Holidays),2,Holidays) + 18/24)
其中所述的H專欄票開日期和後強是你的假期列表。
使用這個基本上沒有節假日的同樣的事情的VBA函數可能會也可能不會更容易/更好。 VBA功能對未來的編程更友好。
Function CalculateDueTime(OpenedTime As Date)
Dim DueTime As Date
Dim wkd As Integer
wkd = Weekday(OpenedTime, vbSunday)
If wkd = 1 Then
'Zero the hours, Add 2 days to get from Sunday to Tuesday, then get to 18:00
DueTime = DateAdd("h", 18, DateAdd("d", 2, DateAdd("h", -Hour(OpenedTime), OpenedTime)))
ElseIf wkd = 7 Then
'Zero the hours, Add 3 days to get from Saturday to Tuesday, then get to 18:00
DueTime = DateAdd("h", 18, DateAdd("d", 3, DateAdd("h", -Hour(OpenedTime), OpenedTime)))
Else
'Add an hours portion to see what day we arrive at
'The reason this works is because what you actually have is an offset in your end-of-day from midnight to EOB.
'So we're accounting for that offset by adding 6 hours then adding 24 to get to our due day,
'then defining 18:00 as our due time on that due day.
DueTime = DateAdd("h", 6 + 24, OpenedTime)
'Whatever day we arrived at above, zero the hours and add 18
DueTime = DateAdd("h", 18, DateAdd("h", -Hour(DueTime), DueTime))
wkd = Weekday(DueTime, vbSunday)
If wkd = 7 Or wkd = 1 Then
'If our due date lands on the weekend
'we can always resolve it by adding 2 days
'Opened Thur due Sat becomes due Mon
'Opened Friday due Sat becomes due Mon
'Opened Friday due Sunday becomes due Tues
DueTime = DateAdd("d", 2, DueTime)
End If
End If
CalculateDueTime = DueTime
End Function
這給了下面的結果...
它並不真正的問題,但如果你好奇的日期格式這裏是我使用的自定義格式。
使用日期/時間戳記,你應該能夠做到這一點。 2017/01/01 15:20的長戳可以評估爲開始時間,然後您確定您是否在2017/01/04 15:20之前完成。您可以使用日期字符串和時間字符串或日期時間字符串進行評估。以你的榜樣爲例,「日」有希望有一個數字,否則你可能需要改變你的評估方式,而週一= 1,週二= 2等。 – Cyril
我剛剛意識到別的事情,我不能簡單地在本週的其餘時間做簡單的計算。如果星期二18:01發生病例,那麼我會在週四16:00之前回復。不知道這是否有意義,但似乎比我原先認爲的複雜一點 – user2429563
感謝Cyril - 我有一個這種格式的列,我解析了所有的東西:1/17/2017 9:02: 21 AM – user2429563