Convert a cell containing time into correct format

Gaetan321

New Member
Joined
Jan 18, 2017
Messages
14
Hello.

I've been googling around for a few hours and searched the forum for an answer.

I have cells containing text "14 hr 05 min 21 sec" and "4 min 20 sec" which I'd like to convert into decimal seconds and I'm looking into the formula but can't find one

Much appreciated
Regards
G
 
here's another for you

With values in column A starting at A2
VBA Code:
Sub TimeIt()
    Dim cel As Range, a As String, b As Variant
    For Each cel In ActiveSheet.Range("A2", ActiveSheet.Range("A" & Rows.Count).End(xlUp))
        On Error Resume Next
        a = LCase(cel)
        If Not InStr(cel, "hr") > 0 Then a = "0 hr " & cel Else a = cel
        a = Replace(Replace(Replace(Replace(a, "hr", "@"), "min", "@"), "sec", ""), " ", "")
        b = Split(a, "@")
        cel.Offset(, 1) = b(0) * 3600 + b(1) * 60 + b(2)
    Next cel
End Sub
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
It just goes to show, that there are multiple ways to remove a feline dermis.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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