0

I would like to copy the time duration (in seconds) to a cell, then have it displayed as (hh:)mm:ss or similar. For example:

Input: 0.49
Display: 0.49 or 0.49s or 490ms (any will do)

Input: 857.26
Display: 14:17 or 14m17s

I know there are ways of doing this 1) when the time duration is entered in hh:mm:ss format, or 2) using a formula/macro to have the content of a cell converted into another cell, where it is shown as desired. I was wondering if it is possible using the format dialog (similarly to custom date/time formats, which I know are possible), so that after filling in a cell the formatting is done "in place".

2
  • 1
    Excel stores times as fractions of a day. So 0.49 = a bit less than 12 hours. Custom number formatting cannot change that. To convert 0.49 to seconds requires dividing that value by 86400 (number of seconds in a day). Then you can format it however you want. But to enter 857.26 into a cell, and have it display as 14:17 , requires VBA to change the actual value in that cell so that the number format can be applied to the correct value. Sep 4, 2021 at 1:04
  • I don't understand how 857.26 becomes 14:17. Generally without vba I'd recommend a separate column for hours, minutes, seconds, ms... then you can combine them in a final column however you want to display the output. It would help if your question was more specific.
    – Jason K.
    Sep 5, 2021 at 5:45

2 Answers 2

1

Hopefully, this will give you some ideas and point you in the right direction.

enter image description here

I see I should have spell checked that, but you'll understand.

1

To convert the value "in-place", select the cells you need to convert and run this macro:

Sub ConvertSecondsToTime()
    Dim r As Range, tm As Double
    Dim v As Double
    v = 86400
    
    For Each r In Selection
        tm = r.Value / v
        r.Value = tm
        r.NumberFormat = "[hh]:mm:ss.000"
    Next r
End Sub

Before:

enter image description here

and after:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .