PC Review


Reply
Thread Tools Rate Thread

Concert number to time

 
 
Patrick C. Simonds
Guest
Posts: n/a
 
      19th Jan 2008
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 With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      19th Jan 2008
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Concert cguil_uk General Discussion 6 25th Apr 2007 07:18 AM
Concert time TriplexDread General Discussion 6 18th Jun 2006 08:24 AM
ripping concert cd's Steve Windows XP Music 3 17th Dec 2003 09:53 AM
concert video FF Windows XP MovieMaker 0 12th Nov 2003 04:44 PM
calculate/concert long/integer to date time Yejeet Microsoft Excel Programming 2 7th Oct 2003 10:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:24 AM.