Convert Time Format to Seconds

paulfitz320

Board Regular
Joined
Jan 6, 2007
Messages
126
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have a column of minutes and seconds in COL A in the following format - 1m 34.47s - Would anyone have a formula or method that can convert these to seconds only in COL B please?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
In standard module eg. Module1 paste the code:
VBA Code:
Function Seconds(ByVal vInput As String) As Double
    Dim dblMins As Double
    Dim dblSecs As Double

    vInput = LCase(vInput)

    If Len(vInput) = 0 Then
        Seconds = 0
    ElseIf InStr(1, vInput, "m", vbTextCompare) > 0 Then
        dblMins = CDbl(Split(vInput, "m")(0))
        dblSecs = CDbl(Val(Split(vInput, "m")(1)))
        Seconds = dblMins * 60 + dblSecs
    ElseIf InStr(1, vInput, "m", vbTextCompare) = 0 Then
        Seconds = CDbl(Val(vInput))
    End If
End Function
In B1 type formula:
Excel Formula:
=Seconds(A1)

Artik
 
Upvote 0
Hi to all.
Supposing you are starting from cell A1 use this formula in cell B1:
=LEFT(A1,FIND("m",A1)-1)*60+MID(A1,FIND("m",A1)+2,LEN(A1)-FIND("m",A1)-2)
 
Upvote 0
Solution
Both worked. Will tick rollis13 as the solution.
Thanks to you both. Much appreciated.
 
Upvote 0
Thanks for the positive feedback(y), glad we were able to help.
 
Upvote 1
My fingers hurt from typing that formula. It is definitely shorter to write =Seconds(A1). ;)
But I'm on another matter. In Poland, this formula will not work because of the decimal separator (in Poland - comma). It would be necessary to expand the formula by replacing the dot with a comma. Leaving this problem aside, with all due respect to rollis13's knowledge, the formula does not stipulate that the string can contain the term only minutes or seconds and redundant spaces. The macro handles these cases perfectly.

Artik
 
Upvote 0
Time 2023.xlsm
ABC
11m 34.47s 94.4794.47
2
3b
Cell Formulas
RangeFormula
B1B1=LET(s,FIND("m",A1)+2,LEFT(A1,FIND("m",A1)-1)*60+MID(A1,s,LEN(A1)-1-s))
C1C1=TEXTBEFORE(A1,"m")*60+TEXTAFTER(TEXTBEFORE(A1,"s"),"m ")
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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