rsmeyerson
Board Regular
- Joined
- Nov 29, 2014
- Messages
- 104
Hello,
I would like help adjusting my code to open a message box if duplicate(s) are found in Column A. The code below opens a message box at each occurrence of a duplicate. I would like the message box to open only once if one or more duplicates are found. Thank you for your help.
I would like help adjusting my code to open a message box if duplicate(s) are found in Column A. The code below opens a message box at each occurrence of a duplicate. I would like the message box to open only once if one or more duplicates are found. Thank you for your help.
VBA Code:
Sub HighlightDuplicates()
Dim cel As Variant
Dim myrng As Range
Dim clr As Long
Set myrng = Range("A2:A" & Range("A65536").End(xlUp).Row)
myrng.Interior.ColorIndex = xlNone
clr = 3
With Sheets("RtlBack")
For Each cel In myrng
If Application.WorksheetFunction.CountIf(myrng, cel) > 1 Then
MsgBox "Duplicate Found"
If WorksheetFunction.CountIf(Range("A2:A" & cel.Row), cel) = 1 Then
cel.Interior.ColorIndex = clr
cel.Interior.TintAndShade = 0.6
clr = clr + 1
Else
cel.Interior.ColorIndex = myrng.Cells(WorksheetFunction.Match(cel.Value, myrng, False), 1).Interior.ColorIndex
cel.Interior.TintAndShade = 0.6
End If
End If
Next
End With
End Sub