I have been working on this project for a while and i’m just getting nowhere so I figured i’d ask you guys here. There are a bunch of tasks: Quoting, Binding, Issuance…and they each have their own response times.
Quoting has to be done within 3 hours, while binding is 8 hours and issuance has a 2 day turnaround time. But, the issue is that the response times are based on only a 9:00 – 8:00 pm (est) time, excluding weekends and holidays. I have a holiday lookup table, as well as the task times indexed from another lookup table.
The part that I’m stuck is in regards to “stopping the clock” and having the task response time turn around to next day if it’s after 8:00 pm.
This is the formula that I created to do so, but it’s not working as it should because it will show the same time if I changed Time to (48,0,0) for issuance or Time(8,0,0) for binding. Column P3 has the start time.
Thank you! Any help will be greatly appreciated guys!
Here’s some untested and not fully implemented code for you to start with:
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
Here are some links that should help you get started with VBA:
You’ll want to test a lot of different scenarios before feeling comfortable with the code. I just put something quick together!