|
これで、どうでしょーか ?
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 WorksheetFunction _
.CountA(Cells(Rc, 6).Resize(, 37)) > 0 Then
Flg = True: GoTo ELine
End If
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 And Not IsEmpty(Cells(Rc, Sc).Value) Then Exit For
If C.Text = Etm Then Ec = C.Column: Exit For
Next
If Sc = 0 Or Ec = 0 Then
Flg = True: GoTo ELine
End If
If CBool(Sc) Xor CBool(Ec) Then
MsgBox "その時間帯は入力済みです", 48
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
|
|