Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Currently, I have a data set which is "mm:ss" and needs to stay / be calculated that way.

The problem is, Microsoft Excel, Google Spreadsheets and OpenCalc all interpret "mm:ss" as "hh:mm" and to add insult to injury add ":ss" (in form of ":00") to anything I copy into Excel/GSheets/Calc.

  1. I have found no way to remove this, except to use "Search and Replace" first ":" then "00" and then at last apply the custom format 0\:00\:00 or 0":"00":"00. (I also tried to get "=Concatenate" to work, but that didn't work for me at all...)

  2. Additionally, using the "0\:00\:00" is in fact only working if I already have a spreadsheet. When I copy the original data (from MS OneNote) into a cell formatted with 0\:00\:00, I don't have the problems described, but the copied data still contains ":", as MS OneNote doesn't have a "Search and Replace" function. My only idea is to take an extra step and copy the data to Notepad and back.

But both approaches are no solution, because my next step should be to sum up those numbers.

Which doesn't work, because any base numbers look like "1234" and not "12:34" (twelve minutes thirty-four seconds, i.e. I am not talking about 12:34 AM/PM (time) but duration!) as they should.

As far as I understood, to sum up minutes properly, I have to use the custom format "[h]:mm:ss", but the problem is that I first have to get the data to (basically) "0:mm:ss" from currently "hh:mm:00". But it is important to remember that those aren't in fact hours! (i.e. /60 doesn't work, because it produces wrong numbers!) The "hh" in question are actually "mm", but because Excel/Calc/GSheets forces their data-interpretation on me without any way of recource of changing this setting, I am out of options.

I never used VBA before, but I am willing to try it.

share|improve this question

migrated from stackoverflow.com Mar 10 '13 at 10:04

This question came from our site for professional and enthusiast programmers.

    
I want to add that I googled around quite a lot, but all solutions that I found were related to simply summing up hh:mm data, which is much easier, if the data base is already (in) hours - inlike mine. –  grunwald2.0 Mar 11 '13 at 14:47

3 Answers 3

I've written a VBA function that will add your minutes and seconds:

Function addTime(rng As Range) As String
    Dim timeArray As Variant
    Dim sumSec As Integer
    Dim sumMin As Integer
    Dim i As Range

    Dim secStr As String
    Dim minStr As String
    Dim hrStr As String

    sumMin = 0
    sumSec = 0

For Each i In rng
        On Error GoTo Continue
        If i.Value <> "" Then
            timeArray = Split(i.Value, ":")
            sumMin = sumMin + timeArray(0)
            sumSec = sumSec + timeArray(1)
        End If
Continue:
        On Error GoTo 0
    Next i

    secStr = Modulo(sumSec, 60)
    If (secStr < 10) Then
        secStr = "0" & secStr
    End If

    minStr = Modulo((sumMin + sumSec \ 60), 60)
    If (minStr < 10) Then
        minStr = "0" & minStr
    End If

    hrStr = sumMin \ 60

    addTime = hrStr & ":" & minStr & ":" & secStr    
End Function

Function Modulo(a, b)
    Modulo = a - (b * (a \ b))
End Function

Put the two functions in a module.

To use my function, first you need to get your data into Excel as-is, i.e. not let Excel change the data into its date-time format. So:

  1. First, click the column(s) you want to paste your data in
  2. Convert the Format to "Text"
  3. Paste your data
  4. Type =addTime(A1:A10) (using "A1:A10" as an example of 10 data points)
share|improve this answer
    
Thanks Amer, I'll try this out ASAP! Sadly I have already irreversibly converted my data from OneNote to Excel at the moment. But I'll it out with a new dataset. –  grunwald2.0 Mar 11 '13 at 14:46

If I understand correctly, then your problem is

1) how to enter hh:ss data without Excel messing it up

2) how to sum them and get the right answer

I know this is a hack, but if you use format [h]:mm, then enter your data, it will work.

Even though you enter minutes and seconds, Excel it will do the math as if it is hours and minutes, but numerically it will give you the answer you want, e.g. 1:45 + 1:30 = 3:15 and 51:45 + 61:30 = 113:15

share|improve this answer
    
hh:ss isn't possible as far as I know. Only hh:mm or mm:ss. What do you mean thus? –  grunwald2.0 Mar 10 '13 at 8:04
    
And I used [h]:mm, but the problem is it won't work properly, because the data base is false! If excel calculates hh:mm, while the actual numbers represent mm:ss, I will get a wrong solution. –  grunwald2.0 Mar 10 '13 at 8:13
    
grunwald2 ... This is confusing. You start by saying "The problem is, Microsoft Excel, Google Spreadsheets and OpenCalc all interpret "mm:ss" as "hh:mm" ", then I show with examples that the math works the same for hh:mm as mm:ss. Next you make a statement "I will get a wrong solution". Can you elaborate and give an example please? –  gabriel Mar 10 '13 at 18:19
    
Well, I actually just noticed IT WORKS correctly after I put the measures in place I described above. But not entirely, because the break-off point seems to be "100" not 60, to when a value is moved to the left. i.e. with a short array of numbers it somehow works, but if they get more, the calculation is off, because both minutes and seconds get /100 not /60 by the SUM function. –  grunwald2.0 Mar 11 '13 at 2:40
    
The problem why your solution doesn't work, that in my case I don't enter the data, MS OneNote does !! So it is automatic, it is already there, i.e. I cannot "prep" the Custom format! -.- And again, I don't want to have to retype all my data, then why do I need excel? Then I'm faster with pen & paper or my manual calculator!! –  grunwald2.0 Mar 11 '13 at 2:42

If you import mm:ss data but excel treats it as hh:mm then you can divide by 60 to convert to the correct mm:ss data.

To divide a whole range of time values by 60 you can use this method:

  1. Put 60 in an empty cell and copy that cell
  2. Select your range of hh:mm values
  3. Right-click and choose "Paste Special" from the menu
  4. In the next dialog box under "Operation" choose "Divide" > OK > ESC
  5. Re-format in the required mm:ss format

Now your values will look the same as before but excel is now treating them as mm:ss as required

This link shows a worksheet with random time values in column A (formatted as [h]:mm) and then columns B & C has the column A value divided by 60 but formatted two different ways - notice how column A looks identical to column C - press F9 to generate different time values

share|improve this answer
    
Nope, Excel doesn't convert 90:15 to 1:30:15, so how is dividing by 60 gonna help? I tried to describe several times that dividing doesn't help. If I e.g. have the value 30:30(:00) (minutes:ss) and divide it by 60, then the new value is - yes - in minutes 00:50:50, which is more than the original value, i.e. totally wrong. –  grunwald2.0 Mar 11 '13 at 2:36
    
@grunwald2.0 -- Have you tested it? I wrote 90:15 into OneNote, copied it into Excel, where it converted to 90:15:00 (hh:mm:ss). Divided by 60 it returned 1:30:15 (hh:mm:ss) or 90:15 formatted with [mm]:ss. Also, I've never, ever seen barry post anything wrong when it comes to time/date issues. –  teylyn Mar 11 '13 at 7:53
1  
Thanks teylyn - I know it works but I tested it before I posted anyway - it certainly worked for me - how do you get 30:30 converted to 00:50:50? If you divide 30 hours by 60 you get half an hour which is 30 minutes, if you divide 30 minutes by 60 you get 30 seconds, so 30:30:00 divided by 60 gives you 00:30:30 as required - what am I missing? –  barry houdini Mar 11 '13 at 10:49
1  
OK, thinking about it I can see that if you have converted a time value 30:30 to a number 3030 then dividing by 60 will give you 50.5 which doesn't help.......the division by 60 has to be applied to the original time values not the "pseudo" time values formatted as 0\:00\:00 –  barry houdini Mar 11 '13 at 11:30
1  
I added a link to my answer - it shows random time values divided by 60 - you can see that any xx:yy hours:mins value is converted to an identical looking xx:yy mins/secs value –  barry houdini Mar 11 '13 at 11:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.