不完善的代码,供参考:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Row = 1 Then Exit Sub
If Target.Column = 3 Or Target.Column > 6 Then Exit Sub
Dim nRow%
If Target.Column = 1 Or Target.Column = 4 Then
rq = Target.Value
je = Target.Offset(, 1).Value
Target.Resize(1, 2).Font.ColorIndex = 0
Else
je = Target.Value
rq = Target.Offset(, -1).Value
Target.Offset(, -1).Resize(1, 2).Font.ColorIndex = 0
End If
With Target
If .Column <= 2 Then
nRow = Range("d65536").End(xlUp).Row
arr = Range("d2:e" & nRow)
Else
nRow = Range("a65536").End(xlUp).Row
arr = Range("a2:b" & nRow)
End If
For i = 1 To nRow - 1
If rq = arr(i, 1) And je = arr(i, 2) Then
If .Column = 1 Or Target.Column = 4 Then
Target.Resize(1, 2).Font.ColorIndex = 3
Else
Target.Offset(, -1).Resize(1, 2).Font.ColorIndex = 3
End If
If .Column <= 2 Then
Range("d" & i + 1).Resize(1, 2).Font.ColorIndex = 3
Else
Range("a" & i + 1).Resize(1, 2).Font.ColorIndex = 3
End If
Exit For
End If
Next
End With
End Sub