Hi,
I can’t remember how to have this time code work in two or more columns.
I think there should to be a “And” at the end of the line below? Then it should work, but that’s not it.
If Application.Intersect(Target, Range("E3:E940")) Is Nothing Then And _
If Application.Intersect(Target, Range("G3:G940")) Is Nothing Then
Exit Sub
End If
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
Any help is appreciated
Dale
I can’t remember how to have this time code work in two or more columns.
I think there should to be a “And” at the end of the line below? Then it should work, but that’s not it.
If Application.Intersect(Target, Range("E3:E940")) Is Nothing Then And _
If Application.Intersect(Target, Range("G3:G940")) Is Nothing Then
Exit Sub
End If
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
Any help is appreciated
Dale
Code:
[SIZE=1]Private Sub Worksheet_Change(ByVal Target As Range)[/SIZE]
[SIZE=1]Dim TimeStr As String[/SIZE]
[SIZE=1] On Error GoTo EndMacro[/SIZE]
[SIZE=1] If Application.Intersect(Target, Range("E3:E940")) Is Nothing Then[/SIZE]
[SIZE=1] Exit Sub[/SIZE]
[SIZE=1] End If[/SIZE]
[SIZE=1] If Target.Cells.Count > 1 Then Exit Sub[/SIZE]
[SIZE=1] If Target.Value = "" Then Exit Sub[/SIZE]
[SIZE=1] Application.EnableEvents = False[/SIZE]
[SIZE=1] With Target[/SIZE]
[SIZE=1] If .HasFormula = False Then[/SIZE]
[SIZE=1] If .Value >= 1 Then[/SIZE]
[SIZE=1] Select Case Len(.Value)[/SIZE]
[SIZE=1] Case 1 ' e.g., 1 = 01:00 AM[/SIZE]
[SIZE=1] TimeStr = Left(.Value, 2) & ":00"[/SIZE]
[SIZE=1] Case 2 ' e.g., 12 = 12:00 AM[/SIZE]
[SIZE=1] TimeStr = .Value & ":00"[/SIZE]
[SIZE=1] Case 3 ' e.g., 123 = 1:23 AM[/SIZE]
[SIZE=1] TimeStr = Left(.Value, 1) & ":" & _[/SIZE]
[SIZE=1] Right(.Value, 2)[/SIZE]
[SIZE=1] Case 4 ' e.g., 1234 = 12:34 AM[/SIZE]
[SIZE=1] TimeStr = Left(.Value, 2) & ":" & _[/SIZE]
[SIZE=1] Right(.Value, 2)[/SIZE]
[SIZE=1] Case Else[/SIZE]
[SIZE=1] Err.Raise 0[/SIZE]
[SIZE=1] End Select[/SIZE]
[SIZE=1] .Value = TimeValue(TimeStr)[/SIZE]
[SIZE=1] End If[/SIZE]
[SIZE=1] .NumberFormat = "h:mm;@"[/SIZE]
[SIZE=1] End If[/SIZE]
[SIZE=1] End With[/SIZE]
[SIZE=1] Application.EnableEvents = True[/SIZE]
[SIZE=1] Exit Sub[/SIZE]
[SIZE=1]EndMacro:[/SIZE]
[SIZE=1] MsgBox "You did not enter a valid time. Please use figures only for the time e.g. 1030"[/SIZE]
[SIZE=1] Application.EnableEvents = True[/SIZE]
[SIZE=1]End Sub[/SIZE]
Last edited: