Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Concert number to time

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Concert number to time

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


"Patrick C. Simonds" wrote in message
...
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


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
Convert time stored as decimalised number to time format Emma New Users to Excel 1 April 29th 08 03:06 PM
time into a number Polochilde Excel Discussion (Misc queries) 6 March 5th 07 04:12 AM
Every time i put a number with period it becomes a date and time excelSOS Excel Discussion (Misc queries) 7 March 7th 06 12:20 AM
calculate/concert long/integer to date time Yejeet Excel Programming 2 October 7th 03 10:39 PM


All times are GMT +1. The time now is 06:32 AM.

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

About Us

"It's about Microsoft Excel"