0

Excel's assumptions about cells are confusing the heck out of me. I'm on Office 365 - Excel for Mac, Version 15.28.

I'm TimeRecording on a lot of things, I would like to calculate relations and tendencies on the different things. I've exported my log-files, and have opened it in excel. A simple version looks like this:

enter image description here

In the real sheet, then I have 40+ tasks and 50+ dates. I would like to be able to do some calculations on these data. But Excel doesn't 'know what it is' (time durations) and therefore can't add them up or do anything.

So one question would be, to how to let Excel know, that this is time durations? I tried doing what this question suggests. But when I format the cells as [h]:mm then it gives me this error:

enter image description here

FYI: In the big sheet, then there's so many times, so the total amounts up to something along the lines of 633:33.

I would just like to be able to do simple calculations, such as:

=SUM(B1, C4, D5)

or

=SUM(B1, C4, D5)/COUNT(B1, C4, D5)

And maybe also make some charts and graphs.

Another attempt I've done is to try to get all the cells to have the format hh.mm instead of hh:mm, but this gave me problems. My approach was this:

  • Convert all the cells to 'Text' to tell Excel: 'Hey... Don't do any auto-converting/guessing here, and don't turn any of the cells into dates or decimal numbers or fricking origami swans!'
  • After that then I make a simple 'Replace all' of : to .
  • But after the 'Replace all', then 633:33 turns into 633.36.00 (even though the cell was a 'Text' cell).
  • And if I then simply double-click on the cell to edit it, then the numbers 'magically' turns from 633.36.00 to 27/01/1900 15.36.00 ... What the hell!? I need a procedure that doesn't require me to go through all my thousands of numbers and edit any of them (or ensure that Excel have turned the numbers into flying unicorns.

EDIT1

Here's an example of the total sheet I'm working on in Google Sheets.

EDIT2

If I format the cells as [h]:mm, then I get an error (see above). But if I format it as [t]:mm, then I don't get an error (thanks to Axel Richter for pointing that out). It may have something to do with the initial language of my Excel-installation (danish). However... If I then try to sum up a bunch of cell, after doing this formatting to everything, then it sums up to 0:00.

If I format all the cells to Time (well-knowing that it's the wrong format, but hoping that Excel can see it and fix it) - and thereafter trying to sum up a couple of cells, then it sums up to 00.00.00 (even though it wasn't empty cells).

Is it also important, that when I sum up some numbers, that I do it from a General-cell - or does Excel know, that if I start with the =-sign, that it's going to be a calculation (and therefore the cell-format doesn't matter)?

Community
  • 1
  • 1
Zeth
  • 2,273
  • 4
  • 43
  • 91
  • `[h]:mm` should work. And no matter how it looks, any time or duration is treated as a date internally. So `sum` or other formulae should work too. Can you provide some excerpt of the log file you want to handle? – Sangbok Lee Mar 06 '17 at 12:06
  • I've made a link to a Google-sheets, where I've copied all the data in. It's in 'EDIT1' in the question. – Zeth Mar 06 '17 at 13:12
  • It doesn't 'solve' your problem, but it may help point you in the right direction. What is happening is excel stores time information as a double and treats it as a fraction of a whole day where 1=24 hours. I tried messing around with doubles in an attempt to solve the issue, but it isnt behaving as I expected it to. You may have better luck on your end. The really frustrating part is that while the underlying value appears as a time (eg "00:15") the actual value is different so parsing using ":" wouldnt work on my end, and conversion to strings had unexpected results. – Brandon Barney Mar 09 '17 at 17:42
  • 1
    Maybe you have a Danish Excel or a English Excel but Danish locale settings in your Windows System? If so then [Formatere tal som datoer eller klokkeslæt](https://support.office.com/da-dk/article/Formatere-tal-som-datoer-eller-klokkesl%C3%A6t-418bd3fe-0577-47c8-8caa-b4d30c528309?ui=da-DK&rs=da-DK&ad=DK#bm2) -> your number format will be `[t]:mm`. – Axel Richter Mar 10 '17 at 10:42
  • It doesn't complain, when I use the format `[t]:mm`. Hmm... That's wierd because everything (including the functions and menu's) are in english. But still, after I use your suggested format, then when I try to sum two times, then it writes `00:00` as the answer. Whaaaat? – Zeth Mar 10 '17 at 13:27
  • What happens if you format your sum cell as `General`? Does it show 0? If so, then your summands are not numeric but text content. – Axel Richter Mar 10 '17 at 14:46
  • Yep, it does show `0` or `00:00`, depending on the cells I'm trying to sum up. What does that mean? That it's trying to sum up strings and not numbers? If so - how do I fix that? – Zeth Mar 11 '17 at 04:45
  • "If so - how do I fix that? ": Simply don't input text ;-). Numbers are aligned to right by default while text is aligned to left by default. So - if the cells are default formatted - you can determine whether Excel will take an input as text or number. Example `123:45` will be a number and aligned to right while `123:67` will be a text and aligned to left since `:67` is not taken as minutes. – Axel Richter Mar 11 '17 at 06:53
  • *Grmbl!* According to your time example `15.36.00` it seems your locale is not Danish (Denmark) but Danish (Greenland). So maybe you have to input `123.45` to input a time of `123:45`. But even if so, my last comment is also correct. Then `123.67` should be taken as text (left aligned). – Axel Richter Mar 11 '17 at 07:25
  • I think I've come close enough to an answer. @AxelRichter , if you post an answer that concludes your comments, then I'll mark that as the answer. It worked if I formatted everything to `[t]:mm` and then made a find/replace of all `:` to `.` (whereafter it wierdly looked the same, such as: `123:45` and not `123.45`). But it works. Thanks! – Zeth Mar 11 '17 at 12:27

5 Answers5

1

Excel will store date-time values as floating point double values in following form:

1 day = 1

1 hour = 1/24 = 0.0416666666666667

1 minute = 1/24/60 = 0.000694444444444444

So formatted as time all values greater than or equal 0 but lower than 1 will be from 00:00 to 23:59. Values greater than 1 will be dates with 1 = 01/01/1900 00:00:00. But if you are formatting such values as time only using hh:mm for example, then only the time is shown. The date is simply hidden.

For example 1.25 formatted using hh:mm will show 06:00 although it is 1 1/4 day which is 01/01/1900 06:00:00. To see hours from multiple days the format [h]:mm can be used. For example 1.25 formatted using [h]:mm will show 30:00 which is 1 day (24:00) + 1/4 day (06:00).

Although Excel will do this independent of locale settings, the user defined format codes used and the kind of input values which Excel will take as time values are dependent of locale settings.

For example with your locale Danish (Greenland) the format codes are different. See Formatere tal som datoer eller klokkeslæt .

So your format code will be [t]:mm instead of [h]:mm.

And also with your locale Danish (Greenland) the time separator is . instead of :. So values which Excel will take as time values are 123.45 (123 hours, 45 minutes) instead of 123:45.

In your last comment you say: "whereafter it weirdly looked the same, such as: 123:45 and not 123.45". Yes that is because your user defined format [t]:mm contains the time separator : also. But that is different from your locale settings where . is the time separator. While inputting values Excel respects the locale settings and so expects 123.45 as time value for 123 hours and 45 minutes. But after the input Excel applies the cell formatting [t]:mm and so shows 123:45.

In your last comment you say that it confuses you that 17:24 * 24 equals 417:36. But that is exactly what it should.

17:24 is 17 hours and 24 minutes. That multiplied by 24 is 17 hours * 24 = 408 hours and 24 minutes * 24 = 576 minutes. 576 minutes are 9 hours and 36 minutes. So we get (408 hours + 9 hours) and 36 minutes = 417 hours and 36 minutes = 417:36.

Axel Richter
  • 56,077
  • 6
  • 60
  • 87
  • I removed that thing from my comment as well. I just did the math and it checks out. Perfect answer. Thanks a lot! – Zeth Mar 11 '17 at 16:04
  • I've just stumbled across another question on this. If I have a cell formatted as `[h].mm` and I go to it and write `1.00`, then it changes it to `24.00`. But if I write `1:00` (notice that the seperator is different) - then Excel changes it to `1.00`. And yep - it is `one DOT zero zero`, even though I typed `one COLON zero zero`. What the hell? – Zeth May 12 '17 at 00:37
  • As stated in my answer and my comments to your question, the time format depends on the locale. So `1.00` in locale Danish (Greenland) will lead to 1 hour 0 minutes in format `[t].mm` since the time delimiter is `.` in that locale. But the same `1.00` in locale English (US or GB) will lead to floating point number `1.00` since the decimal delimiter is `.` in that locale . The floating point number `1.00` is 1 day = 24 hours = `24.00` formatted as `[h].mm`. – Axel Richter May 12 '17 at 03:27
0

I cannot edit the sheet so I copied it. As you can see in column AS and row 43, Google provides 'duration' format. You don't have to manipulate something. Just change the cell format. enter image description here

In Excel, duration format is [h]:mm. Hit ctrl + 1 at the cell and choose Custom and type [h]:mm at Type and hit enter. If SO answer is too difficult to follow, try this.

Sangbok Lee
  • 2,132
  • 3
  • 15
  • 33
  • I would like a solution for Microsoft Excel, since that were I do the majority of my work. Even though that it's cool, that Google Sheets has that option, then that's not how i would like to solve it. If I do what you suggest in Excel, then I get that error, that is in the question ('Cannot use the number format you typed'). – Zeth Mar 09 '17 at 17:04
  • I'm using Excel 2010 and `[h]:mm` works, as I and many people said. (among them [this page](https://office-watch.com/2015/entering-time-durations-in-excel/) again) According to the [help doc](https://support.office.com/en-us/article/Format-numbers-as-dates-or-times-418bd3fe-0577-47c8-8caa-b4d30c528309), it should be working for 2007 to 2016, even for Online. If you have problem using `[h]:mm` cell format, you'd better re-install or repair Excel obviously. – Sangbok Lee Mar 10 '17 at 04:44
0

I apologize in advance for how rough this is, but I mostly slapped this code together to fit the task and didn't want to waste time on it. The principles are there though, so at the least it should point you in the direction you need to be heading.

Sub Time_Summarization()
    Dim i As Long
    Dim j As Long

    Dim cell As Range

    Dim sHolder As String
    Dim vHolder As Variant
    Dim arrHolder() As Double
    Dim bAdd As Boolean

    Dim dHolder_Whole As Double
    Dim dHolder_Remainder As Double

    Dim sOutput As String

    ReDim arrHolder(0 To 2)

    ' Use a set range. Selection here is just for testing
    ' Ideally there should be data validation in this loop to ensure that the input
    ' values are numeric time values.
    For Each cell In Selection
        ' Convert the cell value to a date to permit splitting.
        ' The value is then split into a 1-d array with 3 positions (H, M, S)
        vHolder = Split(CDate(cell.value), ":")

        ' Loop through the split values from first to last, and trim off the AM/PM.
        ' If it is a PM date, set the flag to add 12 (13:00:00 gets displayed as 1:00:00 PM)
        For j = LBound(vHolder) To UBound(vHolder)
            ' If PM, set the flag.
            If InStr(vHolder(j), "PM") Then bAdd = True

            ' Remove "AM" and "PM"
            vHolder(j) = Replace(vHolder(j), " AM", vbNullString)
            vHolder(j) = Replace(vHolder(j), " PM", vbNullString)

            ' Add the values into the array in the same order.
            arrHolder(j) = arrHolder(j) + vHolder(j)
        Next

        ' Add 12 hours if needed
        If bAdd Then arrHolder(0) = arrHolder(0) + 12

        ' Reset the flag for the next loop
        bAdd = False
    Next

    ' Step backwards through the array to round up increments of 60.
    For i = UBound(arrHolder) To LBound(arrHolder) + 1 Step -1
        ' This will return the number of times the value goes into 60.
        dHolder_Whole = arrHolder(i) \ 60

        ' This will return the remainder of the value divided by 60.
        dHolder_Remainder = arrHolder(i) Mod 60

        ' Round up seconds to minutes, and minutes to hours.
        arrHolder(i - 1) = arrHolder(i - 1) + dHolder_Whole

        ' Overwrite the remainder
        arrHolder(i) = dHolder_Remainder
    Next

    ' Combine the separate values into a string.
    sHolder = arrHolder(0) & ":" & arrHolder(1) & ":" & arrHolder(2)

    ' Just for testing, do with the values whatever you wish.
    Debug.Print sHolder
End Sub

Again, this is mostly a model that will work, but will need to be adapted to suit your needs.

Brandon Barney
  • 2,382
  • 1
  • 9
  • 18
  • Holy guacemoly... What language is this? Where (and how) am I supposed to use this? Hmm... – Zeth Mar 11 '17 at 00:19
  • This is VBA which is Microsoft Offices built in language. I thought you were looking for a VBA solution though I realize now you were just generally asking. You can use VBA to solve this problem (as shown above). Otherwise, I am not confident that excel will innately allow you to accomplish your task this way (though pivottable MAY help). – Brandon Barney Mar 12 '17 at 15:05
0

Zeth, I downloaded your file and I can make some calculation with your time data. I juss selected all cell with time duration and change the format of cell to "time". Seemingly you should change all cells format, incluiding the empty cells.

If it does not work, find the "More format of numbers" ate the "Numbers" menu. Then, select the option "Hour" and chose the format closest to the format of your data. Also pay attenction to the option "locality" at the bottom of this menu. The option of hour format deppends on the region selected. (Each region in the world have some convenctions about it and Excel reconize much of then.

Saulo
  • 36
  • 3
  • Hmm... So what do you suggest? Copying everything to a new sheet and try there? Reinstall Excel? – Zeth Mar 11 '17 at 04:43
0

Formatting the numbers does not change the way Excel does calculations.
So a cell (c3) formatted as time and showing 01:28:00 actually contains 0.061111 because Excel treats time as fractions of a 24 hour day.
When you add up a lot of times and they add up to more than 24 hours the underlying number is more than 1 day so you get number of days before the decimal point and after the decimal point is the fraction of 24 hours remaining.
So to convert a duration or time to hours you just multiply it by 24 and format it as a number or general (and the numbers after the decimal point are fractions of an hour).
If you just want to format the result as hours and minutes use a format of [h]:mm and do not multiply by 24 - on your system look at Format Cells - Custom to see what the equivalent of [h:mm] is.

Charles Williams
  • 23,121
  • 5
  • 38
  • 38
  • Interesting! I didn't know that. I can, however, don't get any other sums to get me anything beside `00:00` so far, regardless of what I do. – Zeth Mar 11 '17 at 04:44