automatic formatting

cocacola

New Member
Joined
Oct 16, 2002
Messages
26
hi there

thanks for all your help...

i'm entering a lot of data that looks like:

0:00
0:04
6:20
13:14, etc.

these are number of hours and minutes. is there a formatting shortcut i can use so i don't have to enter the colon and the preceeding zeros for each entry?

in other words, if i enter "1" EXCEL will enter "0:01". if i enter "647", EXCEL will enter "6:47", "100" becomes "1:00", etc.

thanks muchly!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Try this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'   Ignore multiple selection
    If Target.Count > 1 Then Exit Sub
'   Ignore text entries
    If Not IsNumeric(Target.Value) Then Exit Sub
'   Restrict to column A
'   *** Change column number to suit ***
    If Target.Column <> 1 Then Exit Sub
    Application.EnableEvents = False
    Select Case Len(Target)
        Case 1: Target.Value = "0:0" & Target
        Case 2: Target.Value = "0:" & Target
        Case Else: Target.Value = Left(Target, Len(Target) - 2) & ":" & Right(Target, 2)
    End Select
    Target.NumberFormat = "hh:mm"
    Application.EnableEvents = True
End Sub
 

Mark W.

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,654
Not by formatting... Excel needs the colon to recognize the value as one that must be converted into an internal time value, and needing a proper time format; however, you could use a formula (as shown below) to translate an integer value into a corresponding time value.
Book1
ABCDEFGHIJ
16476:47AM
2112:01AM
31001:00AM
4
5
Sheet1

This message was edited by Mark W. on 2002-10-31 10:05
 

Forum statistics

Threads
1,144,509
Messages
5,724,770
Members
422,577
Latest member
kayth891

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
Top