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

Cell U23 has both text and time in it. What I was hoping was that the code
below would change the text to all caps and the number to a time format.


Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ErrHandler:

Application.EnableEvents = False

If Target.Count = 1 And Not Application.Intersect( _
Me.Range("U23"), Target) Is Nothing Then
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Mixed format

Can you show us some samples of the data that could be in cell U23?

Rick


"Patrick C. Simonds" wrote in message
...
Cell U23 has both text and time in it. What I was hoping was that the code
below would change the text to all caps and the number to a time format.


Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ErrHandler:

Application.EnableEvents = False

If Target.Count = 1 And Not Application.Intersect( _
Me.Range("U23"), Target) Is Nothing Then
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Mixed format

Shift starts at 14:30 driving route T


"Rick Rothstein (MVP - VB)" wrote in
message ...
Can you show us some samples of the data that could be in cell U23?

Rick


"Patrick C. Simonds" wrote in message
...
Cell U23 has both text and time in it. What I was hoping was that the
code below would change the text to all caps and the number to a time
format.


Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ErrHandler:

Application.EnableEvents = False

If Target.Count = 1 And Not Application.Intersect( _
Me.Range("U23"), Target) Is Nothing Then
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Mixed format

Does this Change event procedure do what you want?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim X As Long
Dim CellVal As String
Dim Words() As String
If Target.Address = "$U$23" Then
CellVal = UCase(Target.Value)
Words = Split(CellVal, " ")
For X = 0 To UBound(Words)
If Words(X) Like String(Len(Words(X)), "#") _
And Len(Words(X)) < 5 Then
Words(X) = Format(Words(X), "0:00")
End If
Next
CellVal = Join(Words, " ")
On Error GoTo Err_Handler
Application.EnableEvents = False
Target.Value = CellVal
End If
Err_Handler:
Application.EnableEvents = True
End Sub

Rick


"Patrick C. Simonds" wrote in message
...
Shift starts at 14:30 driving route T


"Rick Rothstein (MVP - VB)" wrote in
message ...
Can you show us some samples of the data that could be in cell U23?

Rick


"Patrick C. Simonds" wrote in message
...
Cell U23 has both text and time in it. What I was hoping was that the
code below would change the text to all caps and the number to a time
format.


Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ErrHandler:

Application.EnableEvents = False

If Target.Count = 1 And Not Application.Intersect( _
Me.Range("U23"), Target) Is Nothing Then
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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Mixed format

Unfortunately I can not always count on people to always use upper case
characters and use the time format when entering the time, and that is what
is required.


"Patrick C. Simonds" wrote in message
...
Shift starts at 14:30 driving route T


"Rick Rothstein (MVP - VB)" wrote in
message ...
Can you show us some samples of the data that could be in cell U23?

Rick


"Patrick C. Simonds" wrote in message
...
Cell U23 has both text and time in it. What I was hoping was that the
code below would change the text to all caps and the number to a time
format.


Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ErrHandler:

Application.EnableEvents = False

If Target.Count = 1 And Not Application.Intersect( _
Me.Range("U23"), Target) Is Nothing Then
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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Mixed format

Yes it does. Thank you.


"Rick Rothstein (MVP - VB)" wrote in
message ...
Does this Change event procedure do what you want?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim X As Long
Dim CellVal As String
Dim Words() As String
If Target.Address = "$U$23" Then
CellVal = UCase(Target.Value)
Words = Split(CellVal, " ")
For X = 0 To UBound(Words)
If Words(X) Like String(Len(Words(X)), "#") _
And Len(Words(X)) < 5 Then
Words(X) = Format(Words(X), "0:00")
End If
Next
CellVal = Join(Words, " ")
On Error GoTo Err_Handler
Application.EnableEvents = False
Target.Value = CellVal
End If
Err_Handler:
Application.EnableEvents = True
End Sub

Rick


"Patrick C. Simonds" wrote in message
...
Shift starts at 14:30 driving route T


"Rick Rothstein (MVP - VB)" wrote
in message ...
Can you show us some samples of the data that could be in cell U23?

Rick


"Patrick C. Simonds" wrote in message
...
Cell U23 has both text and time in it. What I was hoping was that the
code below would change the text to all caps and the number to a time
format.


Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ErrHandler:

Application.EnableEvents = False

If Target.Count = 1 And Not Application.Intersect( _
Me.Range("U23"), Target) Is Nothing Then
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




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
Mixed 3D Charts Mark Ivey Charts and Charting in Excel 1 October 5th 06 08:12 PM
format painter wont copy mixed font colors from one cell to next dgc49 Excel Discussion (Misc queries) 6 June 9th 06 01:35 AM
Mixed Cell prbucci Excel Worksheet Functions 2 January 13th 06 03:04 AM
A mixed request Con[_4_] Excel Programming 2 September 12th 05 03:41 AM
A mixed bag of questions Chip Pearson Excel Programming 2 September 13th 03 05:45 PM


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

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"