How to calculate days:Hours:Minutes:

M

Myrna Larson

It could be rewritten to handle a range as an argument. I didn't spend the
time on it because I wasn't sure it you needed it.

If you have to average several hundred cells, then I don't think you're going
to get a formula to do it. It would probably be much too long.

It you are interested in an expanded VBA function, let me know. But before I
spend the time on it, I need some pretty specific information about where the
referenced cells are. Are they all in one row or one column? Or a mix of, say,
100 cells in one column, 25 in another, plus a few scattered cells? Will there
ever be any cells that in fact DON'T contain a date/time in the format you
show? Does the routine need to trap out blank cells, cells containing error
values, and cells containing numbers?


Myrna,

Thanks for the input.

Although handling a VBA solution wouldn't be an issue, I neglected to say
that there could be anywhere between 500 to 1000 referenced cells. If I have
to specify each cell individually, this solution would not be a viable one.
 
D

Daniel.M

Hi,
Just to clarify what you said in regards to being able to use
'1 Days, 2 Hrs, 23 Min' the same as '01 Days, 02 Hrs, 23 Min'...
The formula would have to be greatly modified to take into
account those entries which have a single digit (1) as opposed to two digits
(01)?


If you still insist in a formula solution:

=INT(AVERAGE(MMULT(SUBSTITUTE(MID(A1:A2,SEARCH({"days","hr","min"},
A1)-3,3),",","")/{1,24,1440},{1;1;1})))& "_Days,_" &
TEXT(AVERAGE(MMULT(SUBSTITUTE(MID(A1:A2,SEARCH({"days","hr","min"},
A1)-3,3),",","")/{1,24,1440},{1;1;1})),"hh""_Hr,_""mm""_Min""")

Regards,

Daniel M.
 
M

Myrna Larson

Here is modified code that will handle more than one range, i.e. you could
write

=AverageTimes(J2:J83,J90:J400,"23 Days, 5 Hr, 6Min")

If any of the arguments are not cells containing text in the format you
specified, or literal text in that format, those cells/arguments are treated
as 0. You must specify all 3 pieces, even if the number is 0, i.e. "5 Hr, 10
Min" is illegal -- it has to be "0 Days, 5 Hr, 10 Min".

But I allowed "Day" as well as "Days", it's not case-sensitive, and it's not
fussy about the number or position of spaces [e.g. you have a space before
Days and Hr, but not before "Min"])

Note that the AverageTime function converts each argument to a number, totals
and averages them, and converts the average into the above format.

In my first reply, I explained how to get the code into your workbook. Others
have provided the same information. Good luck!

'~~~~~~~~~~~~~~~~~~~~~~~~~
Option Explicit
Option Base 0

Function AverageTime(ParamArray Durations() As Variant) As String
Dim C As Range
Dim Dur As Double
Dim i As Long
Dim N As Long
Dim Total As Double

N = 0
For i = 0 To UBound(Durations)
'arguments must be a range (1 or more cells) or literal text
Select Case TypeName(Durations(i))
Case "Range"
For Each C In Durations(i).Cells
'ParseDuration will return False if
'the value isn't text in the proper format
If ParseDuration(C.Value, Dur) Then
Total = Total + Dur
N = N + 1
End If
Next C
Case "String"
If ParseDuration((Durations(i)), Dur) Then
Total = Total + Dur
N = N + 1
End If
End Select
Next i

If Total > 0 And N > 0 Then
AverageTime = ConvertToText(Total / N)
Else
AverageTime = ConvertToText(0)
End If

End Function

Private Function ParseDuration(vDuration As Variant, _
nDuration As Double) As Boolean
Dim Components() As String
Dim Divisors As Variant
Dim i As Long
Dim N As Long
Dim Txt As String

nDuration = 0
ParseDuration = False

If TypeName(vDuration) <> "String" Then
Exit Function
Else
Txt = CStr(vDuration) 'put it into a string
Txt = LCase$(Txt) 'convert to lower case
Txt = Replace(Txt, " ", "") 'remove the spaces

'check for text 'Days,' 'Hr,' and ending with Min
If (Txt Like "*days,*hr,*min") = False Then
If (Txt Like "*day,*hr,*min") = False Then
Exit Function
End If
End If
End If

Divisors = Array(1, 24, 1440)

Components() = Split(vDuration, ",")
N = UBound(Components())
'require all 3 pieces to be there
If N <> 2 Then Exit Function

For i = 0 To N
nDuration = nDuration + Val(Components(i)) / Divisors(i)
Next i

ParseDuration = True
End Function

Function ConvertToText(D As Double) As String
ConvertToText = Format$(Fix(D)) & " Days, " _
& Format$(Hour(D)) & " Hrs, " _
& Format$(Minute(D)) & " Min"
End Function

'~~~~~~~~~~~~~~~~~~~~~~~~~
 
M

Myrna Larson

NOW she tells us that she has to do 500-1000 cells! Do you have a formula that
will handle that <vbg> ?
 
D

Daniel.M

Previous one had a couple of errors. Try this one instead:

=INT(AVERAGE(MMULT(SUBSTITUTE(MID(" " &A1:A2,SEARCH({"days","hr","min"},
" " &A1:A2)-3,3),",","")/{1,24,1440},{1;1;1})))& "_Days,_" &
TEXT(AVERAGE(MMULT(SUBSTITUTE(MID(" " &A1:A2,SEARCH({"days","hr","min"},
" " &A1:A2)-3,3),",","")/{1,24,1440},{1;1;1})),"hh""_Hr,_""mm""_Min""")

Regards,

Daniel M.
 
D

Daniel.M

Myrna,
NOW she tells us that she has to do 500-1000 cells! Do you have a formula that
will handle that <vbg> ?

Well, that one work for me anyway:

=INT(AVERAGE(MMULT(SUBSTITUTE(MID(" " &A1:A1000,SEARCH({"days","hr","min"}," "
&A1:A1000)-3,3),",","")/{1,24,1440},{1;1;1})))& "_Days,_" &
TEXT(AVERAGE(MMULT(SUBSTITUTE(MID(" " &A1:A1000,SEARCH({"days","hr","min"}," "
&A1:A1000)-3,3),",","")/{1,24,1440},{1;1;1})),"hh""_Hr,_""mm""_Min""")

MMULT() runs into trouble if you use 70 by 70. When the second array is small,
you can have bigger array as the first arg.

That being said, IMO, the OP should have a little VBA function that splits out
the quantities in 3 cells (one that would also do handling errors, empty cells
input, returning "" strings when appropriate, etc.) and do the calcs from there.

I would also use your VBA code but, hey, not my choice after all. :)

Regards,

Daniel M.
 
M

Myrna Larson

Hi, Daniel:

I would use my macro, too. I handles all of the parsing, error-trapping,
totaling, and averaging internally. No need for the 3 extra columns.

OTOH, the extra columns might be useful if there are errors in the data.

Her life would be simpler if she could get the people who are supplying the
data to put it into a format that's more suitable for calculations.

Myrna Larson
 
G

Guest

Daniel - Myrna,

FYI... I'm a male. :)

My apologies for neglecting to advise that there would be numerous entries to average. Also, my apologies for being such a pain.

The reason I am so set on a formula is that I do not have any VBA experience and that I would prefer to have a single formula in a single cell for simplicty's sake. It very well may a more appropriate to use a VBA solution, but I don't understand it.

Believe me, if I could convince those responsible for generating the data to provide it in a more convenient way, I would. However, I've already run into resistance when trying to modify the format of other data in the report.
 
G

Guest

Ron,

Thank you for the explanation. The UDF works. Sorry to have been a pain. I was able to successfully format it as dd:hh:mm and it produced the same numbers as the formula that Daniel provided. So far, So good.

Now, the issue I was having with Daniel's formula is that it does not work with single numerics inthe entries. The report that generates the data leaves of the preceeding 0 for those entries which contain 0 through 9. (i.e. 5 instead of 05). I have been unable to get his formula to account for that.

The UDF that you provided works for both scenarios. But, the result is different. Given the data below, the results are:
Using preceeding 0's - 23.71239712 or when formatted 23:17:05
Not using preceeding 0's - 23.9715535 or when formatted 23:23:19

Data Set without preceeding 0's
66 Days, 23 Hr, 11Min
0 Days, 0 Hr, 3Min
44 Days, 23 Hr, 6Min
10 Days, 19 Hr, 51Min
12 Days, 1 Hr, 17Min
33 Days, 1 Hr, 21Min
60 Days, 23 Hr, 4Min
0 Days, 0 Hr, 7Min
62 Days, 19 Hr, 19Min
1 Days, 20 Hr, 26Min
4 Days, 4 Hr, 52Min
77 Days, 16 Hr, 58Min
13 Days, 19 Hr, 21Min
24 Days, 1 Hr, 4Min
24 Days, 1 Hr, 6Min
48 Days, 19 Hr, 40Min
1 Days, 2 Hr, 35Min
0 Days, 0 Hr, 5Min
0 Days, 0 Hr, 7Min
0 Days, 0 Hr, 13Min
65 Days, 3 Hr, 31Min
7 Days, 4 Hr, 11Min
0 Days, 0 Hr, 10Min
0 Days, 19 Hr, 20Min
0 Days, 0 Hr, 28Min
55 Days, 18 Hr, 54Min
31 Days, 1 Hr, 14Min
 
G

Guest

Addition to my previous response. Daniels Formula which he updated also produces the same difference when using the entries without preceeding 0's.
 
G

Guest

Daniel,

The Formula that you provided works for both scenarios now. But, the result is different. Given the data below, the results are:
Using preceeding 0's - 23 Days, 17 Hrs, 05 Min
Not using preceeding 0's - 23 Days, 23 Hrs, 19 Min

FYI, Ron Rosenfeld has provided me with some VBA tutoring and a working code. His solution also produces the same results.

Data Set without preceeding 0's
66 Days, 23 Hr, 11Min
0 Days, 0 Hr, 3Min
44 Days, 23 Hr, 6Min
10 Days, 19 Hr, 51Min
12 Days, 1 Hr, 17Min
33 Days, 1 Hr, 21Min
60 Days, 23 Hr, 4Min
0 Days, 0 Hr, 7Min
62 Days, 19 Hr, 19Min
1 Days, 20 Hr, 26Min
4 Days, 4 Hr, 52Min
77 Days, 16 Hr, 58Min
13 Days, 19 Hr, 21Min
24 Days, 1 Hr, 4Min
24 Days, 1 Hr, 6Min
48 Days, 19 Hr, 40Min
1 Days, 2 Hr, 35Min
0 Days, 0 Hr, 5Min
0 Days, 0 Hr, 7Min
0 Days, 0 Hr, 13Min
65 Days, 3 Hr, 31Min
7 Days, 4 Hr, 11Min
0 Days, 0 Hr, 10Min
0 Days, 19 Hr, 20Min
0 Days, 0 Hr, 28Min
55 Days, 18 Hr, 54Min
31 Days, 1 Hr, 14Min
 
G

Guest

Myrna,

Thank You! Ron Rosenfeld gave me some tutoring for VBA and I tested the code. Yours looks to be the closest to what I need. I posted replies to Daniel and Ron regarding their solutions. Yours of course produces the same difference as theirs. If you wouldn't mind, take a look at those replies and let me know what you think.

Thanks again for all the help.

Myrna Larson said:
Here is modified code that will handle more than one range, i.e. you could
write

=AverageTimes(J2:J83,J90:J400,"23 Days, 5 Hr, 6Min")

If any of the arguments are not cells containing text in the format you
specified, or literal text in that format, those cells/arguments are treated
as 0. You must specify all 3 pieces, even if the number is 0, i.e. "5 Hr, 10
Min" is illegal -- it has to be "0 Days, 5 Hr, 10 Min".

But I allowed "Day" as well as "Days", it's not case-sensitive, and it's not
fussy about the number or position of spaces [e.g. you have a space before
Days and Hr, but not before "Min"])

Note that the AverageTime function converts each argument to a number, totals
and averages them, and converts the average into the above format.

In my first reply, I explained how to get the code into your workbook. Others
have provided the same information. Good luck!

'~~~~~~~~~~~~~~~~~~~~~~~~~
Option Explicit
Option Base 0

Function AverageTime(ParamArray Durations() As Variant) As String
Dim C As Range
Dim Dur As Double
Dim i As Long
Dim N As Long
Dim Total As Double

N = 0
For i = 0 To UBound(Durations)
'arguments must be a range (1 or more cells) or literal text
Select Case TypeName(Durations(i))
Case "Range"
For Each C In Durations(i).Cells
'ParseDuration will return False if
'the value isn't text in the proper format
If ParseDuration(C.Value, Dur) Then
Total = Total + Dur
N = N + 1
End If
Next C
Case "String"
If ParseDuration((Durations(i)), Dur) Then
Total = Total + Dur
N = N + 1
End If
End Select
Next i

If Total > 0 And N > 0 Then
AverageTime = ConvertToText(Total / N)
Else
AverageTime = ConvertToText(0)
End If

End Function

Private Function ParseDuration(vDuration As Variant, _
nDuration As Double) As Boolean
Dim Components() As String
Dim Divisors As Variant
Dim i As Long
Dim N As Long
Dim Txt As String

nDuration = 0
ParseDuration = False

If TypeName(vDuration) <> "String" Then
Exit Function
Else
Txt = CStr(vDuration) 'put it into a string
Txt = LCase$(Txt) 'convert to lower case
Txt = Replace(Txt, " ", "") 'remove the spaces

'check for text 'Days,' 'Hr,' and ending with Min
If (Txt Like "*days,*hr,*min") = False Then
If (Txt Like "*day,*hr,*min") = False Then
Exit Function
End If
End If
End If

Divisors = Array(1, 24, 1440)

Components() = Split(vDuration, ",")
N = UBound(Components())
'require all 3 pieces to be there
If N <> 2 Then Exit Function

For i = 0 To N
nDuration = nDuration + Val(Components(i)) / Divisors(i)
Next i

ParseDuration = True
End Function

Function ConvertToText(D As Double) As String
ConvertToText = Format$(Fix(D)) & " Days, " _
& Format$(Hour(D)) & " Hrs, " _
& Format$(Minute(D)) & " Min"
End Function

'~~~~~~~~~~~~~~~~~~~~~~~~~
 
D

Dana DeLouis

Using preceding 0's - 23.71239712 or when formatted 23:17:05
Not using preceding 0's - 23.9715535 or when formatted 23:23:19

I can't add much. The following is similar to Ron's code, and returned
23:19.
I don't know how you want to format it, so I just included something a
little different.

returns:
23 Days 23 Hours 19 Minutes

Function AverageTimes(Rng As Range) As String
Dim v
Dim Cell
Dim Total As Double
Const Fmt As String = "y ""Days "" hh ""Hours"" mm ""Minutes"" "

For Each Cell In Rng
v = Split(Cell, ",")
Total = Total + TimeSerial(24 * Val(v(0)) + Val(v(1)), Val(v(2)), 0)
Next Cell

Total = Total / Rng.Cells.Count
AverageTimes = Format(Total + 1, Fmt)
End Function

HTH
Dana DeLouis


Kurewe said:
Ron,

Thank you for the explanation. The UDF works. Sorry to have been a pain. I
was able to successfully format it as dd:hh:mm and it produced the same
numbers as the formula that Daniel provided. So far, So good.
Now, the issue I was having with Daniel's formula is that it does not work
with single numerics inthe entries. The report that generates the data
leaves of the preceeding 0 for those entries which contain 0 through 9.
(i.e. 5 instead of 05). I have been unable to get his formula to account for
that.
The UDF that you provided works for both scenarios. But, the result is
different. Given the data below, the results are:
Using preceeding 0's - 23.71239712 or when formatted 23:17:05
Not using preceeding 0's - 23.9715535 or when formatted 23:23:19

Data Set without preceeding 0's
66 Days, 23 Hr, 11Min
0 Days, 0 Hr, 3Min
44 Days, 23 Hr, 6Min
10 Days, 19 Hr, 51Min
12 Days, 1 Hr, 17Min
33 Days, 1 Hr, 21Min
60 Days, 23 Hr, 4Min
0 Days, 0 Hr, 7Min
62 Days, 19 Hr, 19Min
1 Days, 20 Hr, 26Min
4 Days, 4 Hr, 52Min
77 Days, 16 Hr, 58Min
13 Days, 19 Hr, 21Min
24 Days, 1 Hr, 4Min
24 Days, 1 Hr, 6Min
48 Days, 19 Hr, 40Min
1 Days, 2 Hr, 35Min
0 Days, 0 Hr, 5Min
0 Days, 0 Hr, 7Min
0 Days, 0 Hr, 13Min
65 Days, 3 Hr, 31Min
7 Days, 4 Hr, 11Min
0 Days, 0 Hr, 10Min
0 Days, 19 Hr, 20Min
0 Days, 0 Hr, 28Min
55 Days, 18 Hr, 54Min
31 Days, 1 Hr, 14Min
module and pasting in the code. However, I have no experience with VBA and
can get no further at the moment.
 
M

Myrna Larson

Hi, MR(!) Kurewe

Sorry for the gender error. I can empathize with your reaction -- many people
for whom English is not their native language don't recognize the "Myrna" is
female. Some years ago I got a hilarious (to me) reaction when after about 3
months, a German man learned that I was a "she" rather than a "he". "Women
don't know anything about math and computers", he said.

I thought I had also explained in my 1st message how to get the code into your
workbook, but maybe not.

What I think: your first result, 23:17:05, is not correct.

To establish that, I did the following:

I pasted the values you show in your other reply (the data without leading
0's) into a worksheet.

I copied it to column B, then used data/text to columns to separate at the
comma into 3 columns. I used search & replace 4 times to remove (a) the
spaces, (b) "days", (c) "hr", (d) "min".

I ended up with all numeric data in columns B:D, as evidenced by the change
from left alignment to right alignment. The original text data is in A1:A27.
The split values in B1:D27 -- days in B, hours in C, minutes in D.

I put some formulas at the bottom:

A30: =AverageTime(A1:A27)
B28: =SUM(B1:B27)+SUM(C1:C27)/24+SUM(D1:D27)/1440
B29: =B28/27
B30: =ConvertToText(B29) (a call to my function to format the result)

The results are, respectively:

A30: 23 Days, 23 Hrs, 19 Min
B28: 647.2319444 (i.e. decimal days, how XL stores dates internally)
B29: 23.9715535 (also decimal days)
B30: 23 Days, 23 Hrs, 19 Min (same as A30)

In F1 I put this formula and copied down through F27:

=TEXT(B1,"00")&" Days, "&TEXT(C1,"00")&" Hr, "&TEXT(D1,"00")&"Min"

This gives me data with leading 0's in F1:F27.

F30: =AverageTime(F1:F27) gives 23 Days, 23 Hrs, 19 Min

I added a new function to the code (see below), to allow you to use a
worksheet formula to just convert the text to a number. Given that, you can
put formulas on the right that convert the data in column A (or that in column
F) to a number. The results are always identical, i.e. the VBA code doesn't
depend on leading 0's.

Function ConvertToDecimal(v As String) As Double
ParseDuration v, ConvertToDecimal
End Function

If you want me to send you the workbook where I did all of this, give me your
email address. If you decide to use my code, you need a workbook like this
anyway, to satisfy yourself that the results are correct. Let me know...

Myrna Larson
Microsoft MVP, Excel


Myrna,

Thank You! Ron Rosenfeld gave me some tutoring for VBA and I tested the code.
Yours looks to be the closest to what I need. I posted replies to Daniel and
Ron regarding their solutions. Yours of course produces the same difference as
theirs. If you wouldn't mind, take a look at those replies and let me know
what you think.
Thanks again for all the help.

Myrna Larson said:
Here is modified code that will handle more than one range, i.e. you could
write

=AverageTimes(J2:J83,J90:J400,"23 Days, 5 Hr, 6Min")

If any of the arguments are not cells containing text in the format you
specified, or literal text in that format, those cells/arguments are treated
as 0. You must specify all 3 pieces, even if the number is 0, i.e. "5 Hr, 10
Min" is illegal -- it has to be "0 Days, 5 Hr, 10 Min".

But I allowed "Day" as well as "Days", it's not case-sensitive, and it's not
fussy about the number or position of spaces [e.g. you have a space before
Days and Hr, but not before "Min"])

Note that the AverageTime function converts each argument to a number, totals
and averages them, and converts the average into the above format.

In my first reply, I explained how to get the code into your workbook. Others
have provided the same information. Good luck!

'~~~~~~~~~~~~~~~~~~~~~~~~~
Option Explicit
Option Base 0

Function AverageTime(ParamArray Durations() As Variant) As String
Dim C As Range
Dim Dur As Double
Dim i As Long
Dim N As Long
Dim Total As Double

N = 0
For i = 0 To UBound(Durations)
'arguments must be a range (1 or more cells) or literal text
Select Case TypeName(Durations(i))
Case "Range"
For Each C In Durations(i).Cells
'ParseDuration will return False if
'the value isn't text in the proper format
If ParseDuration(C.Value, Dur) Then
Total = Total + Dur
N = N + 1
End If
Next C
Case "String"
If ParseDuration((Durations(i)), Dur) Then
Total = Total + Dur
N = N + 1
End If
End Select
Next i

If Total > 0 And N > 0 Then
AverageTime = ConvertToText(Total / N)
Else
AverageTime = ConvertToText(0)
End If

End Function

Private Function ParseDuration(vDuration As Variant, _
nDuration As Double) As Boolean
Dim Components() As String
Dim Divisors As Variant
Dim i As Long
Dim N As Long
Dim Txt As String

nDuration = 0
ParseDuration = False

If TypeName(vDuration) <> "String" Then
Exit Function
Else
Txt = CStr(vDuration) 'put it into a string
Txt = LCase$(Txt) 'convert to lower case
Txt = Replace(Txt, " ", "") 'remove the spaces

'check for text 'Days,' 'Hr,' and ending with Min
If (Txt Like "*days,*hr,*min") = False Then
If (Txt Like "*day,*hr,*min") = False Then
Exit Function
End If
End If
End If

Divisors = Array(1, 24, 1440)

Components() = Split(vDuration, ",")
N = UBound(Components())
'require all 3 pieces to be there
If N <> 2 Then Exit Function

For i = 0 To N
nDuration = nDuration + Val(Components(i)) / Divisors(i)
Next i

ParseDuration = True
End Function

Function ConvertToText(D As Double) As String
ConvertToText = Format$(Fix(D)) & " Days, " _
& Format$(Hour(D)) & " Hrs, " _
& Format$(Minute(D)) & " Min"
End Function

'~~~~~~~~~~~~~~~~~~~~~~~~~
 
M

Myrna Larson

Hi, Dana:

I just posted a message that explains how I demonstrated that 23:17:05 isn't
correct. Must be something wrong with Ron's code, but I haven't looked at it
so find out.

Myrna Larson
 
M

Myrna Larson

All of us started out with no VBA experience, but perhaps you've been given
the perfect opportunity to learn it. There are some things that you just
can't do with worksheet formulas.

I have that same reaction (i.e. "but I don't know anything about that") to
Daniel's MMULT formula. I never had matrix algebra, so it's total Greek to
me.

Myrna Larson


Kurewe said:
Daniel - Myrna,

FYI... I'm a male. :)

My apologies for neglecting to advise that there would be numerous entries
to average. Also, my apologies for being such a pain.
The reason I am so set on a formula is that I do not have any VBA
experience and that I would prefer to have a single formula in a single cell
for simplicty's sake. It very well may a more appropriate to use a VBA
solution, but I don't understand it.
Believe me, if I could convince those responsible for generating the data
to provide it in a more convenient way, I would. However, I've already run
into resistance when trying to modify the format of other data in the
report.
 
M

Myrna Larson

I think at this point it's appropriate to bite the bullet, abandon formulas,
and go with VBA. All of the proposed VBA solutions produce the same
(correct) answer.

Kurewe said:
Addition to my previous response. Daniels Formula which he updated also
produces the same difference when using the entries without preceeding 0's.
 
R

Ron Rosenfeld

The UDF that you provided works for both scenarios. But, the result is different. Given the data below, the results are:
Using preceeding 0's - 23.71239712 or when formatted 23:17:05
Not using preceeding 0's - 23.9715535 or when formatted 23:23:19

I cannot reproduce the error you say you obtain with my UDF when using leading
zeros. I get the same, correct, result (23.9715535) regardless of whether
there are leading zeros or not in the data you posted.

So please post the data that you think is giving erroneous results with my UDF
so we can see exactly what is going on.

======================
I was able to successfully format it as dd:hh:mm

That formatting will ONLY give you a valid result IF and ONLY IF the average
number of days is 31 or less. If your average number of days is greater than
31, your result will not make sense.

So if you are going to deal with averages that are greater than 31 days, you
will need to display them either as a string, or as a decimal number.

To display it as a decimal number, format as General, or as Number with the
desired number of decimal places.

To display it as Text, a formula such as:

=TEXT(INT(averagetimes(A1:A27)),"0 ""days, """)&
TEXT(MOD(averagetimes(A1:A27),1),"h ""Hr, ""m ""Min""")


--ron
 
R

Ron Rosenfeld

Val(v(0)) + Val(v(1)), Val(v(2)), 0)

Neat!

I purposely did not use Split, not knowing what version the OP had; however, I
did not realize that Val would work on strings that started with numeric data.
I need to remember that one.


--ron
 
M

Myrna Larson

And in this case, the "old" way has a definite advantage over CDbl, CLng,
CInt, etc. It stops converting when it hits a character (like the D in Days)
that can't be part of a number. CDbl would give a type-mismatch error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top