Input 4 digits into a cell, convert to [mm]:ss

Jockster

Board Regular
Joined
Jan 16, 2009
Messages
88
Entering time values complete with colons is time consuming.
I am hoping to find a solution to this by being able to enter a four digit number (i.e. 6609) which will be converted to 66:09 in [mm]:ss format.
The times then can be used in calculations.

I have the following code which works well when converting four digits to [hh]:mm format, but I need to adapt it to [mm]:ss and can't figure it out...

Code:
With rCell
    
    Dim Hrs As Integer
    Dim Mins As Integer
    
    '''convert the numeric value to a time value
       Hrs= rCell.Value \ 100
        Mins = rCell.Value Mod 100
        rCell.Value = (Hrs + Mins / 60 / 24)
        rCell.NumberFormat = "[hh]:mm"

End With
Any pointers appreciated!
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Code:
 rCell.Value = (Hrs + Mins / 60) / 24
In my example, this close bracket is in the wrong place.
Doesn't solve my issue though!
 
Upvote 0
Hi, here is one option you could try:

Code:
With rCell
    .Value = Evaluate("0+TEXT(" & .Address & ",""00\:00\:00"")")
    .NumberFormat = "[mm]:ss"
End With
 
Upvote 0
Right-click the sheet's label, view code and paste the following code
Code:
Option Explicit
Const mmssCell As String = "B1" '<=== change to your cell address

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address(0, 0) = mmssCell Then dec2mmss
End Sub

Sub dec2mmss()
    Dim celToConvert As Range
    Dim minutes As Integer
    Dim seconds As Integer
    
    'do not trigger a worksheet_change event _
     by change applied in this sub

    Application.EnableEvents = False
    
    Set celToConvert = Me.Range(mmssCell)
    
    minutes = celToConvert.Value \ 100
    seconds = celToConvert.Value Mod 100
    celToConvert.Value = TimeSerial(0, minutes, seconds)
    celToConvert.NumberFormat = "mm:ss"
    
    Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,244
Messages
6,170,976
Members
452,372
Latest member
Natalie18

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