troubleshooting Question

Remove duplicate strings of characters.

Avatar of Ted Penner
Ted PennerFlag for United States of America asked on
Microsoft OfficeProgrammingVisual Basic ClassicMicrosoft ExcelSpreadsheets
4 Comments1 Solution28 ViewsLast Modified:
If a string of three or more characters appears more than once in the same cell, they should be removed.

This code did part of the work but some items remain and below is a sample of the records that remain.

I'd like to modify this script to catch the remaining cases according to this new logic.

I have attached the macro-enabled file as well as the code.

Assistance is greatly appreciated.

Sub RemoveDuplicateWords()
    Dim r As Range, s As String, arr
    Dim c As Collection

    For Each r In Selection
        Set c = New Collection
        arr = Split(r.Value, " ")
        For i = LBound(arr) To UBound(arr)
            On Error Resume Next
                c.Add arr(i), CStr(arr(i))
            On Error GoTo 0
        Next i

        s = ""
        For i = 1 To c.Count
            s = s & " " & c.Item(i)
        Next i
        If Left(s, 1) = " " Then s = Mid(s, 2)
        r.Value = s
    Next r
End Sub




sample.xlsm
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros