I think you will need a function - see if you can use the code below. The following assumes:
- each day the task is incomplete, that is a duration of 7.25 hours.
- Sunday is the first day of the week in your regional settings
- you only wanted the number of hours based on the work days, having said nothing about partial days (i.e. a task that starts at 2:00 PM one day and finishes at 10:00 AM on the last day). If that is a concern, you would need to used the DateDiff function to get the total hours in the span and subtract 16.75 for each day that aryWrkDays
> 0 AND subtract 24 hours for each day that aryWrkDays
= 0.
Also, Response and ReqDate paraphrase your field names (I'm too lazy to bother with underscores and long names
).
For testing, I hard coded dates for my variables. You can remove the variables and their values (red part) and replace the references in code (blue) to the names of your fields. Somewhere (I have no idea where based on the limited information you supplied) you could call this function using Total_Time_Taken = calcDiff. If you have the dates available at this point, it can be changed to
Total_Time_Taken = calcDiff [Req_Date_Time], [Response_Date_Time] but the first line in the function would have to be
Public Function calcDiff(Req_Date_Time As Date, Response_Date_Time As Date) As Single
Code:
Public Function calcDiff() As Single
Dim daySpan As Integer, n As Integer
Dim aryWrkDays() As Integer
Dim i As Single 'i represents a whole workday
[COLOR=#ff0000]'***********create and set variables for testing; to be removed
Dim Response As Date, ReqDate As Date
Response = #5/17/2016#
ReqDate = #5/1/2016#
'***********[/COLOR]
daySpan = DatePart("d", [COLOR=#0000cd]Response[/COLOR]) - DatePart("d", [COLOR=#0000cd]ReqDate[/COLOR]) + 1 'get # of days
ReDim aryWrkDays(daySpan) 'set array size to span value
For n = 0 To daySpan - 1 'minus 1 because array is zero based
If Weekday([COLOR=#0000cd]ReqDate [/COLOR]+ n) > 0 And Weekday([COLOR=#0000cd]ReqDate [/COLOR]+ n) < 6 Then 'if between Sun. and Thurs. inclusive...
' Debug.Print [COLOR=#0000cd]ReqDate [/COLOR]+ n
aryWrkDays(n) = DatePart("d", ([COLOR=#0000cd]ReqDate [/COLOR]+ n))'...add it to array in 'n' positon
End If
Next
For n = 0 To daySpan -1
'Debug.Print aryWrkDays(n)
If aryWrkDays(n) > 0 Then i = i + 7.25 'zeros=Fri. & Sat., all others are day of week so add 7.25 hrs.
Next
calcDiff = i 'or
End Function