I am trying the following code so as to highlight the duplicates in the same cell
Code: Select all
Sub Highlight_Duplicates_Within_Cell()
Dim s As Variant
Dim sp As Variant
Dim k As Variant
Dim c As Range
Dim dn As Range
Dim n As Long
Set c = Range("A1")
c.Font.Color = vbBlack
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For Each dn In c
sp = Split(dn.Value, ",")
For Each s In sp
If Not .Exists(s) Then
.Add s, 1
Else
.Item(s) = .Item(s) + 1
End If
Next s
Next dn
Dim t As String
For Each dn In c
For Each k In .Keys
t = k & ","
n = 1
Do While InStr(n, dn.Value, t, vbTextCompare) And .Item(k) > 1
dn.Characters(InStr(n, dn.Value, t, vbTextCompare), Len(t)).Font.Color = vbRed
n = n + Len(k)
Loop
Next k
Next dn
End With
End Sub
The duplicate values are 2 and 101
How can I achieve that.. I tried but the result is not totally correct