The macro below creates an error message when an entry is in both columns (P & Q) of a given row. I would like to do the same thing as this, but, instead, if there is an entry in column Q, there MUST be an entry in column R (and vice versa). Just like this existing macro, I would like for it to automatically select the offending cell, but I dont want it to delete the contents of the cell (because its already empty, of course). I suspect that all of this can be accomplished with slight changes to the existing macro, but I'm not sure how to do it. Any help is appreciated.
_____________________________________________________________
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRng As Range, myMsg As String
'if more than 1 cell is changed, exit macro
If Target.Count > 1 Then Exit Sub
'if the changed cell was not in P2:Q1000, exit macro
If Intersect(Target, [P2:Q1000]) Is Nothing Then Exit Sub
'if the new value of the changed cell is blank, exit macro
If Target.Value = "" Then Exit Sub
'otherwise
Application.EnableEvents = False
'detect the column of the changed cell
Select Case Target.Column
Case Is = 16 'column P
Set myRng = Target.Offset(, 1) 'sets cell in column Q as range
myMsg = "Complaint Issue."
Case Is = 17 'column Q
Set myRng = Target.Offset(, -1) 'sets cell in column P as range
myMsg = "NCMR Issue."
End Select
'if the value of the cell opposite the changed cell is not blank
If myRng <> "" Then
With Target
.ClearContents 'delete value entered into changed cell
.Select 'select the changed cell
End With
'display message
MsgBox "There is already an entry in " & myMsg & " An entry can be made as an NCMR or Complaint but not both.", vbOKOnly + vbCritical, "Duplicate Entry"
End If
Application.EnableEvents = True
End Sub
_____________________________________________________________
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRng As Range, myMsg As String
'if more than 1 cell is changed, exit macro
If Target.Count > 1 Then Exit Sub
'if the changed cell was not in P2:Q1000, exit macro
If Intersect(Target, [P2:Q1000]) Is Nothing Then Exit Sub
'if the new value of the changed cell is blank, exit macro
If Target.Value = "" Then Exit Sub
'otherwise
Application.EnableEvents = False
'detect the column of the changed cell
Select Case Target.Column
Case Is = 16 'column P
Set myRng = Target.Offset(, 1) 'sets cell in column Q as range
myMsg = "Complaint Issue."
Case Is = 17 'column Q
Set myRng = Target.Offset(, -1) 'sets cell in column P as range
myMsg = "NCMR Issue."
End Select
'if the value of the cell opposite the changed cell is not blank
If myRng <> "" Then
With Target
.ClearContents 'delete value entered into changed cell
.Select 'select the changed cell
End With
'display message
MsgBox "There is already an entry in " & myMsg & " An entry can be made as an NCMR or Complaint but not both.", vbOKOnly + vbCritical, "Duplicate Entry"
End If
Application.EnableEvents = True
End Sub