LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Entering time values

I had asked for a way to go to a cell, enter a value like "1234" and
have that displayed as "00:12:34". I was given the following snippet of
code:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Range("E4:E27", "F4:F27")) Is Nothing Then Exit
Sub

On Error GoTo errHandler:

With Target
If IsNumeric(.Value) Then
Application.EnableEvents = False
Select Case .Value
Case 0
Case 1 To 99
.Value = TimeSerial(0, 0, .Value)
.NumberFormat = "hh:mm:ss"
Case 100 To 2359
.Value = TimeSerial(0, Int(.Value / 100), .Value Mod
100)
.NumberFormat = "hh:mm:ss"
Case 10000 To 235959
.Value = TimeSerial(Int(.Value / 10000), _
Int((.Value Mod 10000) / 100), .Value Mod 100)
.NumberFormat = "hh:mm:ss"
Case Else
End Select
End If
End With
errHandler:
Application.EnableEvents = True

End Sub


This mostly works, except it seems that if I enter a 4 digit number that
starts with a 3, 4, or 5, I get a weird date.

For example:

3124 gets me 7/20/1908 12:00:00 AM
4567 gets me 7/2/1912 12:00:00 AM

--
John Oliver, CCNA http://www.john-oliver.net/
Linux/UNIX/network consulting http://www.john-oliver.net/resume/
*** sendmail, Apache, ftp, DNS, spam filtering ***
**** Colocation, T1s, web/email/ftp hosting ****


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
 
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
ENTERING TIME Cletus Excel Worksheet Functions 13 June 12th 09 05:50 PM
Entering time C Excel Worksheet Functions 1 June 10th 09 05:10 PM
entering time values Atishoo Excel Discussion (Misc queries) 1 February 12th 09 12:28 PM
Entering time Chris Excel Discussion (Misc queries) 4 June 27th 07 04:50 AM
entering negative time values in excel dona Excel Discussion (Misc queries) 5 March 13th 06 08:23 AM


All times are GMT +1. The time now is 11:01 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"