convert string to specific time format

rossbritton26

New Member
Joined
Jul 28, 2011
Messages
33
hi,

i would like to be able to input a time as ss00 (without any colons, commas or fullstops) and then require the time entered to be formatted and displayed as ss.00.

also, occassionally the times may be just over 1 min so would be something like 1:01.34, i would like to be able to put this in as mss00 and then be formatted and displayed as m:ss.00.

any help would be much appreciated.:)
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
This formula would convert it (doesnt curently work for if you just write s00, has to be ss00, but that can be tweaked)
If your entry was in E4:
Code:
=IFERROR(IFERROR(MID(E4,LEN(E4)-LEN(RIGHT(E4,5)),2),MID(E4,LEN(E4)-LEN(RIGHT(E4,4)),1))&":","")&MID(E4,LEN(E4)-LEN(RIGHT(E4,3)),2)&"."&RIGHT(E4,2)
 
Upvote 0
Have improved on that a bit more. Converted it to VBA so that it will now replace the value you enter with the correct format. Just copy and paste this into your sheets VBA
Code:
Private Sub Worksheet_Change(ByVal Target As Range)Dim numinsert As String, testcell As Range


    Set testcell = Range("E2:E50") 'change this range to the cell range where they will be entering the values you want changing


    If Not Intersect(Target, testcell) Is Nothing Then
   
        If Target.Value Like FormulaR1C1 Or Target.Value Like "*:*" Or Target.Value Like "*.*" Then
        Else
        numinsert = Target.Value
        Debug.Print "=IFERROR(IFERROR(IFERROR(MID(" & numinsert & ",LEN(" & numinsert & ")-LEN(RIGHT(" & numinsert & ",5)),2),MID(" & numinsert & ",LEN(" & numinsert & ")-LEN(RIGHT(" & numinsert & ",4)),1))&"":"","""")&MID(" & numinsert & ",LEN(" & numinsert & ")-LEN(RIGHT(" & numinsert & ",3)),2)&"".""&RIGHT(" & numinsert & ",2),LEFT(" & numinsert & ",1)&"".""&RIGHT(" & numinsert & ",2))"
        Target.FormulaR1C1 = "=IFERROR(IFERROR(IFERROR(MID(" & numinsert & ",LEN(" & numinsert & ")-LEN(RIGHT(" & numinsert & ",5)),2),MID(" & numinsert & ",LEN(" & numinsert & ")-LEN(RIGHT(" & numinsert & ",4)),1))&"":"","""")&MID(" & numinsert & ",LEN(" & numinsert & ")-LEN(RIGHT(" & numinsert & ",3)),2)&"".""&RIGHT(" & numinsert & ",2),LEFT(" & numinsert & ",1)&"".""&RIGHT(" & numinsert & ",2))"
        End If


    End If
End Sub
I also fixed the issue with having s00, so that works now. All you need to do is change the cell range in the code
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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