+ Reply to Thread
Results 1 to 2 of 2

Removing Duplicates from Delimited Content

  1. #1
    Forum Contributor
    Join Date
    07-19-2017
    Location
    usa
    MS-Off Ver
    2016 Professional Plus
    Posts
    128

    Removing Duplicates from Delimited Content

    Hi, I have uploaded an excel file as an attachment which contains two sheets named "before" and "after". The "before" sheet data should be converted to "after" sheet data.

    Actually, in sheet "before" column A, each comma separated value correponds to other comma separated value in column B as one to one correspondence. Now the duplicate values both in cell A1 and B1 which corresponds to each other should be deleted like b corresponds to 2 and c corresponds to 3 in sheet "before" but both of them (b-->2 and c-->3) repeated themselves and so their corresponding values in cell B1. So the duplicates have been removed and the results shown in "After" sheet. I hope you understand my problem. The whole operation could be performed on the same sheet so it is not compulsory that output should be on the new sheet.

    Again Many thanks in advance for the help and your precious time.

    Best Regards,
    Attached Files Attached Files

  2. #2
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Removing Duplicates from Delimited Content

    The only way I know to do this in Excel 2007 is with VBA.

    In the attached find this code already installed for a User Defined Function called CONCATALL. It is written by tigeravatar.

    PHP Code: 
    'tigeravatar ExcelForum
    Public Function ConcatAll(ByVal varData As Variant, Optional ByVal sDelimiter As String = vbNullString, Optional ByVal bUnique As Boolean = False) As String
    '
    Created by TigerAvatar at www.excelforum.comSeptember 2012
    'Purpose is to concatenate many strings into a single string
    '
    Can be used with arraysrange objects, and collections
        
        Dim DataIndex 
    As Variant    'Used to loop through arrays, range objects, and collections
        Dim strResult As String     '
    Used to build the result string
        
        
    'Test if varData is an Array, Range, or Collection
        If IsArray(varData) _
        Or TypeOf varData Is Range _
        Or TypeOf varData Is Collection Then
            
            '
    Found to be an, array, range object, or collection
            
    'Loop through each item in varData
            For Each DataIndex In varData
                '
    Check if the item isn't empty
                If Len(DataIndex) > 0 Then
                    '
    Found the item isn't empty, check if user specified bUnique as True
                    If bUnique = True Then
                        '
    bUnique is truecheck if the item has been included in the result yet
                        
    If InStr(1"||" strResult "||""||" DataIndex "||"vbTextCompare) = 0 Then
                            
    'Item has not been included in the result, add item to the result
                            strResult = strResult & "||" & DataIndex
                        End If
                    Else
                        '
    bUnique is not trueadd item to the result
                        strResult 
    strResult "||" DataIndex
                    End 
    If
                
    End If
            
    Next DataIndex
            
            
    'Correct strResult to remove beginning delimiter and convert "||" to the specified sDelimiter
            strResult = Replace(Mid(strResult, 3), "||", sDelimiter)
            
        Else
            '
    Found not to be an array, range object, or collection
            
    'Simply set the result = varData
            strResult = varData
        End If
        
        '
    Output result
        ConcatAll 
    strResult
        
    End 
    Function 
    Though already installed in the attached here is how that was done.

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the code into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)


    Then this helper formula in C1 that counts the number of elements in the source strings.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Then array entered in D1 and filled across
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    If you aren’t familiar with array-entered formulas array enter means the formula must be committed from edit mode by simultaneously pressing and holding down Ctrl and Shift while hitting Enter.
    Dave

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Remove duplicates function not removing duplicates
    By Berilium2 in forum Excel General
    Replies: 3
    Last Post: 04-01-2015, 06:55 AM
  2. [SOLVED] Counting Delimited Unique Strings and Removing Duplicates
    By The831st in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-30-2014, 11:51 AM
  3. Replies: 2
    Last Post: 09-07-2012, 12:34 PM
  4. Replies: 6
    Last Post: 03-29-2012, 12:16 AM
  5. Remove Duplicates from very large comma delimited Excel file
    By leffler in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 12-12-2011, 07:26 PM
  6. Replies: 4
    Last Post: 09-09-2011, 01:47 PM
  7. Macro to sum all space delimited content of a cell?
    By lexluthor in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-12-2010, 08:05 AM

Tags for this Thread

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