carlrubber
New Member
- Joined
- Oct 15, 2016
- Messages
- 48
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 1 Then Exit Sub
On Error GoTo ErrHandler
Application.ScreenUpdating = False
Dim myDataRng As Range
Dim myDataRng1 As Range
Dim myDataRng2 As Range
Dim cell As Range
' SET THE RANGE (SECOND COLUMN).
Set myDataRng = Range("B1:B" & Cells(Rows.Count, "B").End(xlUp).Row)
Set myDataRng1 = Range("C1:C" & Cells(Rows.Count, "B").End(xlUp).Row)
Set myDataRng2 = Range("D1:D" & Cells(Rows.Count, "B").End(xlUp).Row)
For Each cell In myDataRng
cell.Offset(0, 0).Font.Color = vbBlack ' DEFAULT COLOR.
' LOCATE DUPLICATE VALUE(S) IN THE SPECIFIED RANGE OF DATA.
If Application.Evaluate("COUNTIF(" & myDataRng.Address & "," & cell.Address & ")") > 1 Then
If Application.Evaluate("COUNTIF(" & myDataRng1.Address & "," & Cells(Target.Row, 3).Address & ")") > 1 Then
If Application.Evaluate("COUNTIF(" & myDataRng2.Address & "," & Cells(Target.Row, 4).Address & ")") > 1 Then
cell.Offset(0, 0).Font.Color = vbRed ' CHANGE FORE COLOR TO RED.
End If
End If
End If
Next cell
Set myDataRng = Nothing
ErrHandler:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
I would like to highlight the record that column B C D are exactly the same, but the code show the result, can anyone help?pls
A | B | C | D | E |
aa | bb | cc | ||
bb | bb | cc | ||
bb | bb | cc | ||
bb | dd | ff |
<tbody>
</tbody>