简体   繁体   中英

Hours Calculations in Excel 2010

I have an Excel 2010 workbook which contains a cell with the value of, say, 9876:54:32 (manually entered) representing 9876 hours, 54 minutes and 32 seconds of, say, phone talk time.

Then I have a cell with the value of, say, 1000 (manually entered) representing 1000 calls.

I want to divide the values to get the average talk time of 592.615 minutes per call.

I'm doing a regular =A1/B1 and it gives me an error.

* EDITED * Thanks Brain Webster for correcting my math. I mean 9.876 hours. But the point is that Excel gives me an error, not my manual math. Playing around with it I discovered that Excel is fine with me with values up to 9999:59:59 . Once I try with 10000:00:00 and up, it doesn't recognize it as a time value.

I love these seemingly easy riddles, so here is my solution as a formula and as a VBA attempt:

my original:

= (LINKS(A38;FINDEN(":";A38)-1)/24)+ZEITWERT("0"&RECHTS(A38;LÄNGE(A38)-FINDEN(":";A38)+1))

translated:

= (LEFT(A38,FIND(":",A38)-1)/24)+TIMEVALUE("0"&RIGHT(A38,LEN(A38)-FIND(":",A38)+1))

This will get you the right value to a given 10k text of a time duration. You would only have to setup the format of the cell to [h]:mm:ss . Then those values will look the same, but one would be a string and the other a number - and that is a major difference ;)

In vba it looks much more easier, and once defined, you can use it as a worksheetfunction.

Public Function GetDurationValue(ByVal strInput As String) As Double
  Dim arrResult As Variant

  arrResult = Split(strInput, ":") 'saves you parsing
  GetDurationValue = (arrResult(0) / 24) + _
                     TimeSerial(0, arrResult(1), arrResult(2))

End Function


A38 = "10971:12:14"
=GetDurationValue(A38)
=457.13349537037

You can use LEFT and RIGHT function to retreive parts of the time value and then sum and multiply these values by 60 [minutes] (resp. 3600 [hours]).

Something like this for the hours, minutes, seconds (A1 is the cell with time value):

B1=VALUE(LEFT(A1;FIND(":";A1)))*3600
B2=VALUE(LEFT(A1;FIND(":";A1; FIND(":";A1))))*60
B3=VALUE(LEFT(A1;FIND(":";A1; FIND(":";A1; FIND(":";A1)))))

Now you can sum that:

C1=SUM(B1;B2;B3)

Then divede by calls count (A2 is the cell with the calls count):

D1=C1/A2

Finally format it like time:

E1=TEXT(D1/(24*3600);"d \day\s hh:mm:ss")

BTW: I tried that in Excel 2013 and when I enter 111:22:33 into a cell it automatically converts to a time. So then I can divide it like you try...

It appears that hours > 10000 are not recognised as such by Excel. Therefore we need to introduce an IF() to see whether this is the case and determined the alternative formula for the case where hours >10000

=IF(ISERROR(FIND(":",A2)),A2/B2, <SCRIPT IN CASE OF >10000>)

<SCRIPT IN CASE OF >10000> will now be:

VALUE(LEFT(A2,FIND(":",A2)))/24+VALUE(LEFT(A2,FIND(":",A2, FIND(":",A2))))/(24*60)+VALUE(LEFT(A2,FIND(":",A2, FIND(":",A2,FIND(":",A2)))))*(24*60*60)

combine and enjoy!

Assuming you don't exceed 100,000 hours in A1, and you always display hours, minutes and seconds then this formula should suffice

=IFERROR(A1/B1,(LEFT(A1)*10000/24+RIGHT(A1,10))/B1)

format result cell as [h]:mm:ss to get the result as a time value

With 10971:12:14 in A1 and 1000 in B1 that should give a result of 10:58:16 [or format result cell as [m]:ss to get minutes and seconds like 658:16 ]

This version will work with any number of hours and with or without seconds

=IFERROR(A1/B1,(LEFT(A1,FIND(":",A1)-1)/24+RIGHT(A1&IF(COUNTIF(A1,":*:"),"",":00"),5)/60)/B1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM