Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Concert number to time

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick C. Simonds - 19 Jan 2008 02:44 GMT
I use the code below to force all text to be in upper case. Now I need to
ensure the the number entered in column  Q is converted to a time format.
The time is always entered in the 24 hour format (18:45 = 6:45 pm, 0645 =
6:45 am) but the often forget the  " : ". These cells are not used for
calculations, but they still need to be in the proper format. so is there
any way to force  1845 to me converted to 18:45 or 645 to 06:45 while
ignoring a correctly entered number?

Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.Cells.Count > 1 Then
       Exit Sub
   End If
   On Error GoTo ErrHandler:
   If Not Application.Intersect(Me.Range("G7:P2041"), Target) Is Nothing
Then
       If IsNumeric(Target.Value) = False Then
           Application.EnableEvents = False
           Target.Value = StrConv(Target.Text, vbUpperCase)
        End If
           Application.EnableEvents = True
       End If

ErrHandler:
   Application.EnableEvents = True
End Sub
Rick Rothstein (MVP - VB) - 19 Jan 2008 05:17 GMT
I've modified (and tightened up) your code in order to add the functionality
you asked for... see if this does what you want:

Private Sub Worksheet_Change(ByVal Target As Range)
 On Error GoTo ErrHandler:
 If Target.Count = 1 And Not Application.Intersect( _
      Me.Range("G7:P2041"), Target) Is Nothing Then
   Application.EnableEvents = False
   If IsNumeric(Target.Value) And InStr(Target.Value, ":") = 0 _
                              And Len(Target.Value) < 5 Then
     Target.Value = Format$(Target.Value, "'00\:00")
   Else
     Target.Value = UCase$(Target.Value)
   End If
 End If
ErrHandler:
 Application.EnableEvents = True
End Sub

Rick

>I use the code below to force all text to be in upper case. Now I need to
>ensure the the number entered in column  Q is converted to a time format.
[quoted text clipped - 21 lines]
>    Application.EnableEvents = True
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.