VBA Calculate Turn-around Time

bokboxes

New Member
Joined
Apr 18, 2021
Messages
38
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Column A shows entries date and Column E shows completion date.
I need to average the number of days I took to complete, from entry to completion within a calendar month.

The list below is constantly populated and all are sort by Column A dates.

Two things I need to display,

Average number of days took to complete for previous month.
Average number of days took to complete in the current month.

That will continue for the subsequent months and not limited to April & May only as shown below.

Assumingly both value to be displayed in column K1 & K2.
The value to be in 1 decimal place.

These data in in sheet "TAT".

1621409123682.png
 
I don't understand exactly. Are your weekend day only Thursday? Or ....
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
My formula at Post 3, Column J is appropriate for you with this example that you show.


With that formula , I calculate the difference between average of Column A & Column E based Month at Column A. And this is exact what you want.
Kindly refer to post #3, row 10 for example.

That extended over the weekends. And I need to exclude weekends.
I don't understand exactly. Are your weekend day only Thursday? Or ....
weekend days are Saturday & Sunday. We probably in different time zone.
lets say,

Workdays are Monday to Friday.
Non-workdays are Saturday & Sunday

Assuming,
Start day = Friday
End day = Tuesday

That technically is 5 days but in fact, weekends are not included.
So Turnaround Time = 3 days. (Friday, Monday & Tuesday)

Can we do that?
 
Upvote 0
I calculate it with Networkday. But Networkday calculate one day more than you need I think. ( Test Networkdays function yourself to see result).
If I correct, Use formula at Column N, if you want exact days that calculate Networkdays function, Use Column J Formula.
With this situation, Only Formula way I think is use Sumproduct, And for calculate at total column take time to respond. if your data not Large change all column value to Range you have Data. Example if your Data is in Rows 2:50 Change all A:A to $A$2:$A$50 & E:E to $E$2:$E$50.
if you want we can also define macro for it also, that one should be more quicker.
Book1.xlsx
ABCDEFGHIJKLMN
1Month No.Month NameAverage number of days took to CompleteAverage number of days took to Complete
24/14/20214/17/20214April2.7647061.764706
34/15/20214/17/20215May3.0555562.055556
44/16/20214/20/2021
54/17/20214/20/2021
64/18/20214/20/2021
74/19/20214/23/2021
84/20/20214/23/2021
94/21/20214/23/2021
104/22/20214/26/2021
114/23/20214/26/2021
124/24/20214/26/2021
134/25/20214/29/2021
144/26/20214/29/2021
154/27/20214/29/2021
164/28/20215/2/2021
174/29/20215/2/2021
184/30/20215/2/2021
195/1/20215/5/2021
205/2/20215/5/2021
215/3/20215/5/2021
225/4/20215/8/2021
235/5/20215/8/2021
245/6/20215/8/2021
255/7/20215/11/2021
265/8/20215/11/2021
275/9/20215/11/2021
285/10/20215/14/2021
295/11/20215/14/2021
305/12/20215/14/2021
315/13/20215/17/2021
325/14/20215/17/2021
335/15/20215/17/2021
345/16/20215/20/2021
355/17/20215/20/2021
365/18/20215/21/2021
37
Sheet1
Cell Formulas
RangeFormula
H2H2=MONTH(TODAY())-1
I2I2=TEXT(EOMONTH(TODAY(),-1),"MMMM")
J2J2=SUMPRODUCT(NETWORKDAYS(A:A+0,E:E+0)*(MONTH(A:A)=MONTH(TODAY())-1))/SUMPRODUCT(1*(MONTH(A:$A)=MONTH(TODAY())-1))
H3H3=MONTH(TODAY())
I3I3=TEXT(TODAY(),"MMMM")
J3J3=SUMPRODUCT(NETWORKDAYS(A:A+0,E:E+0)*(MONTH(A:A)=MONTH(TODAY())))/SUMPRODUCT(1*(MONTH(A:$A)=MONTH(TODAY())))
L2L2=(SUMPRODUCT(NETWORKDAYS(A:A+0,E:E+0)*(MONTH(A:A)=MONTH(TODAY())-1))/SUMPRODUCT(1*(MONTH(A:$A)=MONTH(TODAY())-1)))-1
L3L3=(SUMPRODUCT(NETWORKDAYS(A:A+0,E:E+0)*(MONTH(A:A)=MONTH(TODAY())))/SUMPRODUCT(1*(MONTH(A:$A)=MONTH(TODAY()))))-1
E2,E35:E36,E32,E29,E26,E23,E20,E17,E14,E11,E8,E5E2=A2+3
E3,E33,E30,E27,E24,E21,E18,E15,E12,E9,E6E3=A3+2
E4,E34,E31,E28,E25,E22,E19,E16,E13,E10,E7E4=A4+4
 
Upvote 0
I calculate it with Networkday. But Networkday calculate one day more than you need I think. ( Test Networkdays function yourself to see result).
If I correct, Use formula at Column N, if you want exact days that calculate Networkdays function, Use Column J Formula.
With this situation, Only Formula way I think is use Sumproduct, And for calculate at total column take time to respond. if your data not Large change all column value to Range you have Data. Example if your Data is in Rows 2:50 Change all A:A to $A$2:$A$50 & E:E to $E$2:$E$50.
if you want we can also define macro for it also, that one should be more quicker.
Book1.xlsx
ABCDEFGHIJKLMN
1Month No.Month NameAverage number of days took to CompleteAverage number of days took to Complete
24/14/20214/17/20214April2.7647061.764706
34/15/20214/17/20215May3.0555562.055556
44/16/20214/20/2021
54/17/20214/20/2021
64/18/20214/20/2021
74/19/20214/23/2021
84/20/20214/23/2021
94/21/20214/23/2021
104/22/20214/26/2021
114/23/20214/26/2021
124/24/20214/26/2021
134/25/20214/29/2021
144/26/20214/29/2021
154/27/20214/29/2021
164/28/20215/2/2021
174/29/20215/2/2021
184/30/20215/2/2021
195/1/20215/5/2021
205/2/20215/5/2021
215/3/20215/5/2021
225/4/20215/8/2021
235/5/20215/8/2021
245/6/20215/8/2021
255/7/20215/11/2021
265/8/20215/11/2021
275/9/20215/11/2021
285/10/20215/14/2021
295/11/20215/14/2021
305/12/20215/14/2021
315/13/20215/17/2021
325/14/20215/17/2021
335/15/20215/17/2021
345/16/20215/20/2021
355/17/20215/20/2021
365/18/20215/21/2021
37
Sheet1
Cell Formulas
RangeFormula
H2H2=MONTH(TODAY())-1
I2I2=TEXT(EOMONTH(TODAY(),-1),"MMMM")
J2J2=SUMPRODUCT(NETWORKDAYS(A:A+0,E:E+0)*(MONTH(A:A)=MONTH(TODAY())-1))/SUMPRODUCT(1*(MONTH(A:$A)=MONTH(TODAY())-1))
H3H3=MONTH(TODAY())
I3I3=TEXT(TODAY(),"MMMM")
J3J3=SUMPRODUCT(NETWORKDAYS(A:A+0,E:E+0)*(MONTH(A:A)=MONTH(TODAY())))/SUMPRODUCT(1*(MONTH(A:$A)=MONTH(TODAY())))
L2L2=(SUMPRODUCT(NETWORKDAYS(A:A+0,E:E+0)*(MONTH(A:A)=MONTH(TODAY())-1))/SUMPRODUCT(1*(MONTH(A:$A)=MONTH(TODAY())-1)))-1
L3L3=(SUMPRODUCT(NETWORKDAYS(A:A+0,E:E+0)*(MONTH(A:A)=MONTH(TODAY())))/SUMPRODUCT(1*(MONTH(A:$A)=MONTH(TODAY()))))-1
E2,E35:E36,E32,E29,E26,E23,E20,E17,E14,E11,E8,E5E2=A2+3
E3,E33,E30,E27,E24,E21,E18,E15,E12,E9,E6E3=A3+2
E4,E34,E31,E28,E25,E22,E19,E16,E13,E10,E7E4=A4+4
I think macro will work better.
This is what I have got.

1621565603771.png


The value got larger compared to previous, and a negative value.

Can we do VBA code then?
 
Upvote 0
For Current month, I think at the last rows you have rows that have data at column A But column E is Empty then , you see Negative Result.
Please tell me at the previous post you want result at Column J format Or Column L format.
 
Upvote 0
This is Macro. You should define You want J column Or L column Values.

After that, I change macro to Worksheet Change event to When you add value at column E, Macro run And recalculate Values you want for last two Month.

VBA Code:
Sub TaskWorkDays()
Dim i As Long, Lr As Long, J As String, K As Long, N1 As Long, N2 As Long
Dim M1 As Long, M2 As Long, T1 As String, T2 As String
Lr = Range("E" & Rows.Count).End(xlUp).Row
K = Month(Date)
For i = 2 To Lr
Select Case Month(Range("A" & i).Value)
 Case K - 1
  M1 = M1 + Application.WorksheetFunction.NetworkDays(Range("A" & i).Value, Range("E" & i).Value)
  N1 = N1 + 1
 Case K
  M2 = M2 + Application.WorksheetFunction.NetworkDays(Range("A" & i).Value, Range("E" & i).Value)
  N2 = N2 + 1
 End Select
Next i
Range("J2").Value = M1 / N1
Range("J3").Value = M2 / N2
Range("L2").Value = (M1 / N1) - 1
Range("L3").Value = (M2 / N2) - 1
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,974
Messages
6,122,536
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top