| 
    
     |  | こちらでテストしたかぎり、以下のコードでうまくいきました。 
 Private Sub Worksheet_Change(ByVal Target As Range)
 Dim Stm As String, Etm As String, Unm As String
 Dim Sc As Integer, Ec As Integer, Rc As Long
 Dim Flg As Boolean
 Dim C As Range
 
 If Intersect(Target, Range("E6:E65536").SpecialCells(-4174)) _
 Is Nothing Then Exit Sub
 With Target
 If .Count > 1 Then Exit Sub
 If IsEmpty(.Offset(, -1).Value) Then Exit Sub
 If Not .Validation.Value Then
 Flg = True: GoTo ELine
 End If
 Rc = .Row
 If .Offset(, -1).Value > .Value Then
 Flg = True: GoTo ELine
 End If
 Range("D6:E65536").SpecialCells(-4174).NumberFormat = "h:mm"
 Stm = .Offset(, -1).Text
 Etm = .Text
 End With
 For Each C In Range("F4:AP4")
 If C.Text = Stm Then Sc = C.Column
 If Sc > 0 Then
 If Not IsEmpty(Cells(Rc, Sc).Value) Then
 MsgBox "その時間帯は入力済みです", 48: Exit Sub
 End If
 End If
 If C.Text = Etm Then Ec = C.Column: Exit For
 Next
 If Sc = 0 Or Ec = 0 Then
 Flg = True: GoTo ELine
 End If
 Do
 Unm = InputBox("氏名を入力して下さい")
 Loop While Unm = ""
 ELine:
 Application.EnableEvents = False
 If Flg Then
 MsgBox "入力した値は条件に一致しません。" & _
 "クリアして終了します", 48
 Else
 Range(Cells(Rc, Sc), Cells(Rc, Ec)).Value = Unm
 End If
 Cells(Rc, 4).Resize(, 2).ClearContents
 Application.EnableEvents = True
 End Sub
 
 |  |