+ Reply to Thread
Results 1 to 11 of 11

Finding and removing duplicate wording in each row of Excel

Hybrid View

  1. #1
    Registered User
    Join Date
    06-04-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Finding and removing duplicate wording in each row of Excel

    Hi, I'm new here so I'm not sure how to go about this. I've been searching around on the forum but I couldn't quite seem to get the answer I needed for my particular situation. So here I have 3 columns of data. I am trying to delete the duplicate words from Column A and B that are in Column C. I am trying to find a quick, automated way to do this for 1000+ entries. Does anyone have any ideas? Much appreciated.


    ExcelForum Example.xlsx

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Finding and removing duplicate wording in each row of Excel

    Hi,

    like this or the other way around? For the other way you have to define a separation string like a comma or a space, but try
    Sub RemoveDuplicateWords()
        Dim i As Long
        With ActiveSheet
            For i = 1 To .Cells(.Rows.Count, 1).End(xlUp).Row   'from row 1 to last row with data
                If InStr(.Cells(i, 3).Value, .Cells(i, 1).Value) > 0 Then
                    .Cells(i, 3).Value = Trim(Replace(.Cells(i, 3).Value, .Cells(i, 1).Value, vbNullString))
                End If
                If InStr(.Cells(i, 3).Value, .Cells(i, 2).Value) > 0 Then
                    .Cells(i, 3).Value = Trim(Replace(.Cells(i, 3).Value, .Cells(i, 2).Value, vbNullString))
                End If
            Next i
        End With
    End Sub
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    06-04-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Finding and removing duplicate wording in each row of Excel

    Ah sorry, I messed up in the excel sheet. So with the format I have currently in the sheet, I want to remove the second "Cooler Master CO., LTD." and "RR-LIE-L9E1-GP".

    @tehneXus Where would I add the separation string? Does that mean I have to add it to each entry?

    ExcelForum Example.xlsx

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Finding and removing duplicate wording in each row of Excel

    Isn't it

    =TRIM(SUBSTITUTE(SUBSTITUTE(C1,A1,"",2),B1,"",2))

    ?

  5. #5
    Registered User
    Join Date
    06-04-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Finding and removing duplicate wording in each row of Excel

    @jindon I tried your method and but it doesn't exactly work for my purposes.


    1. SEAGATE TECHNOLOGY


    2. STBU500102


    3. SEAGATE TECHNOLOGY STBU500102 SEAGATEBACKUPPLUSP


    Say if that was in each respective Column 1, 2, and 3. I was wondering if it's possible to automate excel to scan column 3 for that second "SEAGATE" word and remove it while leaving the "BAKCUPPLUSP".

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Finding and removing duplicate wording in each row of Excel

    Then UDF

    Use in cell like

    =RemoveNthLikeWords(C1,2,A1,B1)

    Where ;
    C1 = whole string to be processed
    2 = reference # for n th from the start
    A1,B1 = contains string to be removed and you can add more like A1,B1,D1,F1.... etc

    To a standard module
    Function RemoveNthLikeWords(txt As String, n As Long, ParamArray a()) As String
        Dim e, s
        For Each e In a
            For Each s In Split(e)
                txt = Application.Substitute(txt, s, "", n)
            Next
        Next
        RemoveNthLikeWords = txt
    End Function

  7. #7
    Registered User
    Join Date
    06-04-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Finding and removing duplicate wording in each row of Excel

    Thanks jindon. Your function seems to work for most of the data.

    However I came across some cells where the function didn't seem to work? I had to change the 'n reference' # to fix that cell but I would I have go through every cell to double check. Is there a fix for that?

    For data like:

    1. LSI LOGIC CORPORATION

    2. LSI00182

    3. LSI LOGIC CORPORATION LSI00182 LSI SAS3081E-R SINGLE PACK

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Finding and removing duplicate wording in each row of Excel

    How do want the result?

  9. #9
    Registered User
    Join Date
    06-04-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Finding and removing duplicate wording in each row of Excel

    If possible, I want it to look like

    LSI LOGIC CORPORATION LSI00182 SAS3081E-R SINGLE PACK

    so the second "LSI" is removed.

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Finding and removing duplicate wording in each row of Excel

    Try change to

    =TRIM(RemoveLastLikeWords(C1,A1,B1))

    Function RemoveLastLikeWords(txt As String, ParamArray a()) As String
        Dim e, s, m As Object
        With CreateObject("VBScript.RegExp")
            .Global = True
            .IgnoreCase = True
            For Each e In a
                For Each s In Split(e)
                    .Pattern = "\b" & Trim$(s)
                    If .test(txt) Then
                        Set m = .Execute(txt)
                        If m.Count > 1 Then
                            txt = Application.Substitute(txt, Trim$(s), "", m.Count)
                        End If
                    End If
                Next
            Next
        End With
        RemoveLastLikeWords = txt
    End Function

  11. #11
    Registered User
    Join Date
    06-04-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Finding and removing duplicate wording in each row of Excel

    That's perfect! Thanks jindon

+ 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