#1   Report Post  
Oonagh
 
Posts: n/a
Default time format

How do I format a column so that when I put in 6 digit numbers they will
automatically format as hh:mm:ss? When using the Format Cells option and then
Time hh:mm:ss, the digits appear as 00:00:00 when you tab out of the cell.
  #2   Report Post  
Harald Staff
 
Posts: n/a
Default

You can't.
1 is a day in Excel. 12 hours is half a day, 0.5.
You want to enter 120000 (which to Excel is 120 000 days, more than 300
years) and suddenly it is 0.5.
Formatting does not change content that way. You need a macro solution.
There's one at Chip's page
http://www.cpearson.com/excel/DateTimeEntry.htm

HTH. Best wishes Harald


"Oonagh" skrev i melding
...
How do I format a column so that when I put in 6 digit numbers they will
automatically format as hh:mm:ss? When using the Format Cells option and

then
Time hh:mm:ss, the digits appear as 00:00:00 when you tab out of the cell.



  #3   Report Post  
Jason Morin
 
Posts: n/a
Default

Assuming column A, format the column as text, then use
this code:

Private Sub Worksheet_Change(ByVal Target As Range)

With Target

If .Column < 1 Then Exit Sub 'col A=1,B=2,etc.
If .Count 1 Then Exit Sub
Application.EnableEvents = False

If IsNumeric(.Value) Then
If Len(.Value) < 6 Then
MsgBox "Please enter 6 numbers."
GoTo ExitThisSub
ElseIf Left(.Value, 2) 24 Or _
Mid(.Value, 3, 2) 59 Or _
Right(.Value, 2) 59 Then
MsgBox "The maximum time allowed " & _
"is 23:59:59."
GoTo ExitThisSub
End If
Else
MsgBox "Invalid entry."
GoTo ExitThisSub
End If

.NumberFormat = "General"
.Value = TimeSerial(Left(.Value, 2), _
Mid(.Value, 3, 2), Right(.Value, 2))
.NumberFormat = "[hh]:mm:ss"
Application.EnableEvents = True
Exit Sub

ExitThisSub:
.ClearContents
.Select
Application.EnableEvents = True
Exit Sub

End With

End Sub

---
To use the code, right-click on the worksheet tab, go to
View Code, and paste in the code above. Press ALT+Q to
close.

HTH
Jason
Atlanta, GA

-----Original Message-----
How do I format a column so that when I put in 6 digit

numbers they will
automatically format as hh:mm:ss? When using the Format

Cells option and then
Time hh:mm:ss, the digits appear as 00:00:00 when you

tab out of the cell.
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove time from a date and time field? Format removes the displa. oaoboc Excel Worksheet Functions 1 February 16th 05 07:20 PM
Custom Time Format doesn't work for me chuck Excel Discussion (Misc queries) 1 February 13th 05 04:12 AM
I cannot get time format to display in a drop-down list Mighty Mike Excel Discussion (Misc queries) 0 February 1st 05 09:47 PM
entering numbers to display a time format Ian Williams/Eazygig Excel Discussion (Misc queries) 1 January 10th 05 11:57 AM
Time Format Auto Entry AM and PM BulaMan Excel Discussion (Misc queries) 1 December 15th 04 09:30 AM


All times are GMT +1. The time now is 05:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"