Duplicate entries in a CELL

dhally

Board Regular
Joined
May 9, 2011
Messages
58
Hello,
I have a range of cells (H2:H3398). Some cells contain duplicate entries for example: HENRICH; OLD #3175460; UCI1089-CABLES, OLD #3175460 .

Not all cells contain duplicate entries however.

Is there a formula for removing unwanted duplicate entries as indicated in the red font through the range of cells?
 
Here is the code with some commenting to help you better understand.

Code:
Public Sub RemoveDupEntries()
Dim i       As Long, _
    j       As Long, _
    LR      As Long, _
    temparr As Variant, _
    temp    As String, _
    delim   As String
'Change application settings to speed up code
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
' Variable Initialization
delim = ","
LR = Range("H" & Rows.Count).End(xlUp).Row
'Loop through the range
For i = 2 To LR
    'Displays a visual progression indicator in the status bar.
    Application.StatusBar = "Currently checking row " & i & " of " & LR
    'Check to see if current cell is populated
    If Len(Range("H" & i).Value) > 0 Then
        'Create a 1-dimensional array using the Split function, which splits the
        '  current cell's value into separate entries based on the delimiter.
        '    Value: Current Cell
        '    Delimiter: delim variable (defined in the variable initialization)
        temparr = Split(Range("H" & i).Value, delim)
        'Loop through the array created by the Split function
        For j = LBound(temparr) To UBound(temparr)
            'Check to see if the current element of the array is already a part of the temp
            '  variable.  If it is not a part of the temp variable, then add it
            If InStr(temp, temparr(j)) = 0 Then
                temp = temp & temparr(j) & delim & " "
            End If
        Next j
        'Removes the two right characters of the temp variable if needed prior to storing it in the current cell
        If Right$(temp, 2) = delim & " " Then
            Range("H" & i).Value = Left$(temp, Len(temp) - 2)
        Else
            Range("H" & i).Value = temp
        End If
    End If
    'Removes all entries from the array created by Split, and resets temp to a null string
    Erase temparr
    temp = ""
Next i
'Reset various application settings
With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
    .StatusBar = False
End With
End Sub
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,224,606
Messages
6,179,862
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top