如何获得在周转周末和下班后的响应时间?

时间:2018-08-09 15:35:08

标签: excel excel-formula

我已经在这个项目上工作了一段时间,但是我却一无所获,所以我想在这里问你们。有很多任务:报价,绑定,签发...它们各自都有自己的响应时间。

报价必须在3个小时内完成,而绑定则需要8个小时,并且发行需要2天的周转时间。但是,问题在于响应时间仅基于(东部时间)晚上9:00-8:00(不包括周末和节假日)。我有一个假期查询表,以及从另一个查询表索引的任务时间。

我停留的部分是关于“停止计时”,如果在晚上8:00之后,则将任务响应时间调到第二天。

这是我创建的公式,但不能正常运行,因为如果我将“发行”的“时间”更改为(48,0,0)或“时间(8,0,0)”,它将显示相同的时间)进行绑定。 P3列具有开始时间。

=IF(AND(TEXT(P3,"dddd")="Friday",HOUR(P3)+MINUTE(P3)/60+SECOND(P3)/(60*60)>17),P3+TIME(15,0,0)+DAY(2),IF(HOUR(P3)+MINUTE(P3)/60+SECOND(P3)/(60*60)>17,P3+TIME(15,0,0),P3+Time(3,0,0)))

谢谢!任何帮助将不胜感激的家伙!

1 个答案:

答案 0 :(得分:2)

下面是一些未经测试且未完全实现的代码,供您开始:

Function GetTurnaroundDateAndTime(TaskType As String, StartTime As Date, TaskTimeRange As Range, HolidayLookupRange As Range)
    Dim taskTime As Double
    Dim dayBegin As Double 'could be a parameter
    Dim dayEnd As Double 'could be a parameter
    Dim result As Date
    Dim isValid As Boolean
    Dim offset As Double

    dayBegin = 9 'could be a parameter
    dayEnd = 20 'could be a parameter
    offest = 0

    'Get Task Time in hours
    taskTime = GetTaskTime(TaskType, TaskTimeRange)

    'Calculate initial turnaround time (without regard to nights/weekends/holidays)
    result = DateAdd("h", taskTime + offset, StartTime)

    'check if it's a valid turnaround date and time, return if so
    isValid = False
    Do While isValid = False
        'check #1 - is the turnaround time before the day begins?
        If Hour(result) < 9 Then
            If Hour(StartTime) < 20 Then
                offset = offset - 20 + Hour(StartTime) 'check to see if a portion of the task time would be before end of day, subtract this amount from the offset
            End If
            offset = offset + 9 = Hour(result) 'gets the offset to the beginning of day
        ElseIf Weekday(result, vbSaturday) = 1 Then
            offset = offset + 48 'if we're on a Saturday, add two days
        ElseIf Weekday(result, vbSunday) = 1 Then
            offset = offset + 24 'if we're on a Sunday, add one day
        ElseIf IsHoliday(result, HolidayLookupRange) Then
            offset = offset + 24 'if we're on a holiday, add one day
        Else
            isValid = True
        End If

        result = DateAdd("h", taskTime + offset, StartTime) 're-evaluate result
    Loop

    GetTurnaroundDateAndTime = result
End Function

Function GetTaskTime(TaskType As String, TaskTimeRange As Range) As Double
    'TODO: implement function to lookup the task time from the table
    GetTaskTime = 3
End Function

Function IsHoliday(DateToLookup As Date, HolidayLookupRange As Range) As Boolean
    'TODO: implement function to lookup if date is a holiday
    IsHoliday = False
End Function

以下一些链接应可帮助您开始使用VBA:

您需要先对很多不同的场景进行测试,然后才能熟悉代码。我只是把一些东西放在一起!