Thanks for the response. Unfortunately, for reasons of confidentiality, I can't submit the sheet.
Procedure 1 is 'designed' so that if a cell (range name "Course") is changed (a new course is selected from a drop-down menu) the student's name also must be changed so a message advises this.
Procedure 2 below is a clever bit of code (needless to say, not written by me) which allows easy entry of time values when a numeric value is entered in a particular range ("Time") of cells .
The code for both is contained in the sheet, not in a module.
I hope this is enough to establish the error of my ways...
Thanks
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim TimeStr As String
On Error GoTo EndMacro
If Application.Intersect(Target, Range("Time")) Is Nothing Then
Exit Sub
End If
If Target.Cells.Count > 1 Then
Exit Sub
End If
If Target.Value = "" Then
Exit Sub
End If
Application.EnableEvents = False
With Target
If .HasFormula = False Then
Select Case Len(.Value)
Case 1
TimeStr = "00:0" & .Value
Case 2
TimeStr = "00:" & .Value
Case 3
TimeStr = Left(.Value, 1) & ":" & _
Right(.Value, 2)
Case 4
TimeStr = Left(.Value, 2) & ":" & _
Right(.Value, 2)
Case 5
TimeStr = Left(.Value, 1) & ":" & _
Mid(.Value, 2, 2) & ":" & Right(.Value, 2)
Case 6
TimeStr = Left(.Value, 2) & ":" & _
Mid(.Value, 3, 2) & ":" & Right(.Value, 2)
Case Else
Err.Raise 0
End Select
.Value = TimeValue(TimeStr)
End If
End With
Application.EnableEvents = True
Exit Sub
EndMacro:
MsgBox "You did not enter a valid time"
Application.EnableEvents = True
End Sub
Bookmarks