Format cell containing elapsed time to show days hours and minutes

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,283
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good morning,
I have a cell that contains the following value: 01/01/1900 06:58:27 which equates to 1 day 6 hours and 58 minutes.
Is there any formatting sequence I can use to get the cell to display "1d 6h 58m", rather than the "30h 58m" that I have at the moment, using [hh]"h" mm"m"
I'm using Excel 2016.
Thanks in advance
Pete
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I would play with checking the length value, so If greater than 1 get the integer value for days, then look at the remainder. Don't have anything quick to hand
 
Upvote 0
Excel version (answer in a different cell)
Code:
=INT(N36) & "d " & MID(TEXT(N36, "hh mm ss"), 1, 2) & "h " & MID(TEXT(N36, "hh mm ss"), 4, 2) & "m " & MID(TEXT(N36, "hh mm ss"), 7, 2) & "s "

VBA version (replace existing values in current selection)
Code:
Sub ElapsedTimesToStrings()
    Dim MyCell As Range
    Dim MyString As String
    For Each MyCell In Selection
        With MyCell
            .FormulaR1C1 = Int(MyCell.Value) & "d " & Mid(Format(MyCell.Formula, "hh mm ss"), 1, 2) & "h " & Mid(Format(MyCell.Formula, "hh mm ss"), 4, 2) & "m " & Mid(Format(MyCell.Formula, "hh mm ss"), 7, 2) & "s "            
            .HorizontalAlignment = xlRight
        End With
    Next
End Sub

Thanks for your suggestions that helped me to arrive at this!

Pete
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top