I have been using the below macro to automatically add a semi colon when time is entered and it works great, but today I it errored. if I activate a cell within my named range "Time" and set the focus within the cell with the cursor and before I change the focus to a new cell I select another sheet within the workbook the macro bugs stating, "Method intersect of object_Global failed" Can anyone tell me what I could add to avoid this error? Thank you.
Code:
Sub EnterTime(Target)
If Target.Cells.CountLarge > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
If Intersect(Target, Range("Time" & ActiveSheet.Index)) Is Nothing Then Exit Sub
Application.EnableEvents = False
With Target
If Not .HasFormula And IsNumeric(.Value) And .Value < 2400 Then
.Value = TimeValue(Format(.Value, "00:00"))
Else
.Value = ""
With ErrMsg
.Label1.Caption = "Error:" & vbNewLine _
& "The time entered was not valid"
.Show
End With
End If
End With
Application.EnableEvents = True
End Sub