Hi all
I have a worksheet where, in one of the columns, we need to remove any duplicate values. The values are separated by a ;
At the moment, I have found the following:
This is mostly working, except where a duplicate value exists at the beginning of the cell, and is not preceded by a ;.PHP Code:
Sub RemoveDupesInCell()
Dim dic As Object, cell As Range, temp As Variant
Dim i As Long
Set dic = CreateObject("scripting.dictionary")
With dic
For Each cell In Range("BB1:BB" & Cells(Rows.Count, "BB").End(xlUp).Row)
.RemoveAll
If Len(cell.Value) > 0 Then
temp = Split(" " & cell.Value, ";")
For i = 0 To UBound(temp)
If Not .Exists(temp(i)) Then .Add temp(i), temp(i)
Next i
cell.Value = Mid(Join(.Keys, ";"), 2)
End If
Next cell
End With
End Sub
So, if I have:
duplicate;duplicate;duplicate;duplicate
it will turn into
duplicate;duplicate
If I have:
duplicate;duplicate
it remains the same.
Does anybody know what I am missing in this?
Thanks!!
Bookmarks