Convert time from #h #m #s format

chusk1

New Member
Joined
Oct 6, 2015
Messages
1
I am trying to sort a column by duration of time. The format the cell is in is #h #m #s. This causes it to sort by the first number only.

How can I convert the time to HH:MM:SS format?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Excel won't accept what you have provided as a valid number format. But I'm not sure that would cause a problem as the underlying value would still be the same decimal value.
Can you post an example?
 
Upvote 0
If data is in time format multiply it by 86400 which will convert it into seconds and then sort with this coloumn
 
Upvote 0
If your times are actually text values (instead of time values formatted to look that way), then give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub FixTimeValues()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Range("A1:A" & LastRow) = Evaluate(Replace("IF(LEN(A1:A#),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1:A#,""h "","":""),""m "","":""),""s"",""""),"""")", "#", LastRow))
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,214,806
Messages
6,121,667
Members
449,045
Latest member
Marcus05

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