I need to calculate business hours elapsed in MS Excel. Here i have two dates, start and End date with respective timings. Some places i might not have end date and timings. Business hours are 7AM EST - 17 PM EST. how can i calculate number of business hours elapsed here ? (Excluding Weekends)
Tried "=IF(ISBLANK(P2),(NETWORKDAYS(O2,NOW())-1)*("17:00"-"7:00")+IF(NETWORKDAYS(NOW(),NOW()),MEDIAN(MOD(NOW(),1),"17:00","7:00"),"17:00")-MEDIAN(NETWORKDAYS(O2,O2)MOD(O2,1),"17:00","7:00"),(NETWORKDAYS(O2,P2)-1)("17:00"-"7:00")+IF(NETWORKDAYS(P2,P2),MEDIAN(MOD(P2,1),"17:00","7:00"),"17:00")-MEDIAN(NETWORKDAYS(O2,O2)*MOD(O2,1),"17:00","7:00"))", need to exclude holidays as well here.
You can split this into three components (fraction of first day, full workdays, fraction of last day)
Lets start with the middle part. Here you can use NETWORKDAYS and subtract the start and end date. I am assuming a start date in A1 and end date in B1. In order to exclude holidays you need to maintain a list of holidays in your sheet. The formula assumes that this list is in range C1:C10. The results is multiplied by 10 as there are 10 hours in your workday.
=MAX((NETWORKDAYS(A1,B1,C1:C10)-NETWORKDAYS(A1,A1,C1:C10)-NETWORKDAYS(B1,B1,C1:C10))*10,0)
For the fractions you will need to determine if the day itself is a holiday, we use the NETWORKDAYS function again as a factor which will be either 0 or 1. Now we only need to determine the hours to add for the day. Depending on the granularity you want you can consider hours, minutes or even seconds. I will use hours and minutes as a fraction (minutes/60 = hours).
For the first day you get
=MAX(17-MAX(HOUR(A1)+MINUTE(A1)/60,10),0)*NETWORKDAYS(A1,A1,C1:C10)
For the last day you get
=MAX(MIN(HOUR(B1)+MINUTE(B1)/60,17)-10,0)*NETWORKDAYS(B1,B1,C1:C10)
Putting it all together leaves us with:
=MAX(17-MAX(HOUR(A1)+MINUTE(A1)/60,10),0)*NETWORKDAYS(A1,A1,C1:C10)+MAX((NETWORKDAYS(A1,B1,C1:C10)-NETWORKDAYS(A1,A1,C1:C10)-NETWORKDAYS(B1,B1,C1:C10))*10,0)+MAX(MIN(HOUR(B1)+MINUTE(B1)/60,10)-10,0)*NETWORKDAYS(B1,B1,C1:C10)
I believe this UDF will do what you need.
It calculates the hours and returns it as a float, then you need to multiply that with 24 to get the hours.
Function workhours(startdate As Date, enddate As Date)
Opentime = "7:00"
Closetime = "17:00"
Fulldays = Int(enddate - startdate) - 1
DayOneHours = CDate(Year(startdate) & "-" & Month(startdate) & "-" & Day(startdate) & " " & Closetime) - startdate
BeforeOpen = CDate(Year(startdate) & "-" & Month(startdate) & "-" & Day(startdate) & " " & Opentime) - startdate
HoursDayOne = DayOneHours - BeforeOpen
If enddate < CDate(Year(enddate) & "-" & Month(enddate) & "-" & Day(enddate) & " " & Opentime) Then
HoursLastDay = 0
Else
HoursLastDay = enddate - CDate(Year(enddate) & "-" & Month(enddate) & "-" & Day(enddate) & " " & Opentime)
End If
workhours = Fulldays * (CDate(Closetime) - CDate(Opentime)) + HoursDayOne + HoursLastDay
End Function
Use it in Excel like:
=workhours(A1,B1)*24
So I have this formula source here
=REPT(CHAR(9); CODE(A1)-65) & SUMPRODUCT(($A$1:$A$200="A")*(ROW($A$1:$A$200)<=ROW(A1)-1)) & "." & IF(CODE(A1)>65;SUMPRODUCT(($A$1:$A$200="B")*(ROW($A$1:$A$200)<=ROW(A1))*(ROW($A$1:$A$200)>=MAX(ROW($A$1:$A$200)*($A$1:$A$200="A")*(ROW($A$1:$A$200)<=ROW(A1))))) & ".";"") & IF(CODE(A1)>66;SUMPRODUCT(($A$1:$A$200="C")*(ROW($A$1:$A$200)<=ROW(A1))*(ROW($A$1:$A$200)>=MAX(ROW($A$1:$A$200)*($A$1:$A$200="B")*(ROW($A$1:$A$200)<=ROW(A1))))) & ".";"") & CHAR(9) & B1
Which give us this:
The question is: How do I start from 0?
Starting from zero mean,
Title 1 = 0. Title 1
Title 2 = 1. Title 2
Subtitle 3 = 1.1 Subtitle 3
Just found the solution, you need too Subtract 1 from the first SUMPRODUCT
Thanks for you help everyone
=REPT(CHAR(9); CODE(A1)-65) & SUMPRODUCT(($A$1:$A$200="A")*(ROW($A$1:$A$200)<=ROW(A1)))-1 & "." & IF(CODE(A1)>65;SUMPRODUCT(($A$1:$A$200="B")*(ROW($A$1:$A$200)<=ROW(A1))*(ROW($A$1:$A$200)>=MAX(ROW($A$1:$A$200)*($A$1:$A$200="A")*(ROW($A$1:$A$200)<=ROW(A1))))) & ".";"") & IF(CODE(A1)>66;SUMPRODUCT(($A$1:$A$200="C")*(ROW($A$1:$A$200)<=ROW(A1))*(ROW($A$1:$A$200)>=MAX(ROW($A$1:$A$200)*($A$1:$A$200="B")*(ROW($A$1:$A$200)<=ROW(A1))))) & ".";"") & CHAR(9) & B1
In general, to create a column of values starting from zero and increasing by one, pick any cell and enter:
=ROWS($1:1)-1
and copy downward.
I have the date and time in the following format in Excel:- 12Jun17/1802 How do I convert this to excel date and time format? I have tried Format Custom but I am unable to make this work.
Excel stores dates and times as days and fractions of a day since 1/1/1900. The string you show is being seen only as text.
One way to convert it is to use string functions to format it into something Excel will recognize as a date/time:
=LEFT(A2,2) & " " & MID(A2,3,3) & " " & MID(A2,6,2) & " " & TEXT(RIGHT(A2,4),"00\:00")
--> 12 Jun 17 08:02
and then convert that to a number:
=--(LEFT(A2,2) & " " & MID(A2,3,3) & " " & MID(A2,6,2) & " " & TEXT(RIGHT(A2,4),"00\:00"))
You can now format that number with any of the date/time formats.
I've defined the following formula in Excel
=DATEDIF(B595;TODAY();"y") & " years, " & DATEDIF(B595;TODAY();"ym") & " months, " & DATEDIF(B595;TODAY();"md") & " days"
But it shows a result like:
0 years, 0 months, 20 days
I would prefer to see:
20 days
Can I use a VBA function to get a nicer result? Or a formula?
Just add If statements to the formula that will remove the component if DateDif evaluates to zero:
=IF(DATEDIF(B595;TODAY();"y")=0;"";DATEDIF(B595;TODAY();"y") & " years, ") & _
IF(DATEDIF(B595;TODAY();"ym")=0;"";DATEDIF(B595;TODAY();"ym") & " months, ") & _
IF(DATEDIF(B595;TODAY();"md")=0;"";DATEDIF(B595;TODAY();"md") & " days, ")
I broke the formula into three lines so its readable here, but it should be inputted as one line
This is what I am needing to put into Column A
= B1 & " " & C1 & " " & D1 & " " & E1 & " " & F1 & " " & G1 & " " & H1 & " " & I1
wherein the numbers will correspond to the current row that it is pasted in. Is there a faster way than simply pasting it in and manually changing the 1's to 2's, or to 3's or to 37892's?
You would string together a bunch of formulas:
=INDEX(B:B,Row()) & " " & INDEX(C:C,Row()) & ...
But if all you want is to put the formula in J1 and copy it down, then use your original formula. Put it in J1. then do one of the following:
Click on the lower right corner and drag down as far as you want.
Highlight J1 and all the cells below in which you want the formula. Go to Fill --> Down
Either of these will automatically change the row number on your original formula.