+ Reply to Thread
Results 1 to 6 of 6

Drop duplicate values from string

Hybrid View

  1. #1
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Drop duplicate values from string

    With
    A2:F2 containing numbers or blanks
    Try this formula...
    G2: =SUBSTITUTE(TRIM(A2&" "&IF(B2=A2,"",B2)&" "&
    IF(COUNTIF(A2:B2,C2),"",C2)&" "&IF(COUNTIF(A2:C2,D2),"",D2)&" "&
    IF(COUNTIF(A2:D2,E2),"",E2)&" "&IF(COUNTIF(A2:E2,F2),"",F2))," ","~")
    If it get messier than that, I'd recommend creating
    a User Defined Function (UDF) with VBA.

    I hope that helps.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    UDF, if you like...
    1) hit Alt + F11
    2) go to [Insert] - [Module] then paste the code onto the right pane
    3) hit Alt + F11 again to get back to Excel
    Use in cell like
    =sc0tt(A1:Z10,"~")
    Function sc0tt(rng As Range, JoinString As String) As String
    Dim r As Range
    With CreateObject("Scripting.Dictionary")
        .CompareMode = vbTextCompare
        For Each r In rng
            If (r.Value <> "") * (Not .exists(r.Text))) Then _
                sc0tt = sc0tt & IIf(sc0tt <> "", JoinString, "") & r.Text
        Next
    End With
    End Function

  3. #3
    Registered User
    Join Date
    06-12-2008
    Posts
    14

    Talking wow

    I would have never been able to figure that out in a millions years. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1