C
Corey
~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Worksheet_SelectionChange(ByVal target As Range)
Const WS_RANGE1 As String =
"C11,C15,F11,F15,I11,I15,L11,L15,O11,O15,R11,R15,U11,U15"
Const WS_RANGE2 As String =
"C8,C12,F8,F12,I8,I12,L8,L12,O8,O12,R8,R12,U8,U12"
Const msg As String = _
"There is an overlap in the Times Entered." & vbNewLine & _
"The next Start Time needs to be equal or greater than the previous
Finish Time."
If Not Intersect(target, Range(WS_RANGE1)) Is Nothing Then
If target.Value = "" Or target.Offset(-3, 0).Value = "" Then
Exit Sub
End If
If target.Offset(-3, 0).Value > target.Value And _
target.Offset(-2, 0).Value <> Range("V17").Value Then
MsgBox msg, , "...."
target.Offset(0, 0).ClearContents
target.Offset(0, 0).Select
End If
ElseIf Not Intersect(target, Range(WS_RANGE2)) Is Nothing Then
If target.Value = "" Or target.Offset(-2, 0).Value = "" Then
Exit Sub
End If
If target.Value < target.Offset(-2, 0).Value And _
target.Value < Range("V17").Value Then
MsgBox msg, , "...."
target.ClearContents
target.Select
End If
End If
End Sub
~~~~~~~~~~~~~~~~~~~~~~
Code above works well, but i need to re-enter the cell to get it to work.
How can i have it work as i leave the cell in that range instead.
I have other code in the :
Private Sub Worksheet_Change(ByVal target As Excel.Range)
section.
Corey....
Private Sub Worksheet_SelectionChange(ByVal target As Range)
Const WS_RANGE1 As String =
"C11,C15,F11,F15,I11,I15,L11,L15,O11,O15,R11,R15,U11,U15"
Const WS_RANGE2 As String =
"C8,C12,F8,F12,I8,I12,L8,L12,O8,O12,R8,R12,U8,U12"
Const msg As String = _
"There is an overlap in the Times Entered." & vbNewLine & _
"The next Start Time needs to be equal or greater than the previous
Finish Time."
If Not Intersect(target, Range(WS_RANGE1)) Is Nothing Then
If target.Value = "" Or target.Offset(-3, 0).Value = "" Then
Exit Sub
End If
If target.Offset(-3, 0).Value > target.Value And _
target.Offset(-2, 0).Value <> Range("V17").Value Then
MsgBox msg, , "...."
target.Offset(0, 0).ClearContents
target.Offset(0, 0).Select
End If
ElseIf Not Intersect(target, Range(WS_RANGE2)) Is Nothing Then
If target.Value = "" Or target.Offset(-2, 0).Value = "" Then
Exit Sub
End If
If target.Value < target.Offset(-2, 0).Value And _
target.Value < Range("V17").Value Then
MsgBox msg, , "...."
target.ClearContents
target.Select
End If
End If
End Sub
~~~~~~~~~~~~~~~~~~~~~~
Code above works well, but i need to re-enter the cell to get it to work.
How can i have it work as i leave the cell in that range instead.
I have other code in the :
Private Sub Worksheet_Change(ByVal target As Excel.Range)
section.
Corey....