Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim i As Integer
    Dim lastRow As Long
    Dim res1 As String
    Dim res2 As String
    
    
    With Worksheets("E")
    lastRow = .UsedRange.Rows.Count
    For i = 2 To lastRow
        If .Cells(i, "A").Value = "買物" Or .Cells(i, "A").Value = "外出" Or _
            .Cells(i, "A").Value = "帰宅" Or .Cells(i, "A").Value = "遅刻" Then
            If .Cells(i, "B").Value = "" Then
                res1 = .Cells(1, "B").Value
                .Cells(i, "B").Interior.ColorIndex = 3
            Else
                .Cells(i, "B").Interior.ColorIndex = xlNone
            End If
            If .Cells(i, "C").Value = "" Then
                res2 = .Cells(1, "C").Value
                .Cells(i, "C").Interior.ColorIndex = 3
            Else
                .Cells(i, "C").Interior.ColorIndex = xlNone
            End If
        Else
            .Range(.Cells(i, "A"), .Cells(i, "C")).Interior.ColorIndex = xlNone
        End If
    Next i
    End With
    
    If res1 <> "" Or res2 <> "" Then
        If res1 <> "" And res2 <> "" Then
            res2 = "と" & res2
        End If
        MsgBox res1 & res2 & "を入力してください", vbExclamation
        Cancel = True
    End If
End Sub