Please can you give me some advice on why the following Change event will not work? It dose not seem to run.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
It is place in the worksheet module that it needs to work in.<o></o>
It is a procedure to convert an entry to military time format. EG 1800 become 18:00.<o></o>
Even when entering 2370, it will not bring up the error messages.<o></o>
<o></o>
It did previously work but now not. (Excel 2003)
<o>Private Sub Worksheet_Change(ByVal Target As Range)</o>
<o>Dim TimeStr As String
On Error Resume Next
If Application.Intersect(Target, Range("L4:GG6")) Is Nothing Then
Application.EnableEvents = False
Exit Sub
End If
If Target.Cells.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
If Not IsNumeric(Target.Value) Then Exit Sub
If Left(Target.Value, 2) > 23 Or Right(Target.Value, 2) > 59 Then
MsgBox "Please Enter A Valid Time value 0000 - 2359"
Target = ""
Target.Activate
Application.EnableEvents = True
Exit Sub
End If
Application.EnableEvents = False
With Target
UserInput = Format(Target.Value, "00:00")
If Len(UserInput) > 1 Then
NewInput = Left(UserInput, Len(UserInput) - 2) & ":" & Right(UserInput, 2)
Application.EnableEvents = False
Target = UserInput
Application.EnableEvents = True
End If
End With
End Sub</o>
Many thanks
Malcolm
It is place in the worksheet module that it needs to work in.<o></o>
It is a procedure to convert an entry to military time format. EG 1800 become 18:00.<o></o>
Even when entering 2370, it will not bring up the error messages.<o></o>
<o></o>
It did previously work but now not. (Excel 2003)
<o>Private Sub Worksheet_Change(ByVal Target As Range)</o>
<o>Dim TimeStr As String
On Error Resume Next
If Application.Intersect(Target, Range("L4:GG6")) Is Nothing Then
Application.EnableEvents = False
Exit Sub
End If
If Target.Cells.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
If Not IsNumeric(Target.Value) Then Exit Sub
If Left(Target.Value, 2) > 23 Or Right(Target.Value, 2) > 59 Then
MsgBox "Please Enter A Valid Time value 0000 - 2359"
Target = ""
Target.Activate
Application.EnableEvents = True
Exit Sub
End If
Application.EnableEvents = False
With Target
UserInput = Format(Target.Value, "00:00")
If Len(UserInput) > 1 Then
NewInput = Left(UserInput, Len(UserInput) - 2) & ":" & Right(UserInput, 2)
Application.EnableEvents = False
Target = UserInput
Application.EnableEvents = True
End If
End With
End Sub</o>
Many thanks
Malcolm
Last edited: