+ Reply to Thread
Results 1 to 16 of 16

Remove Duplicates Function for Single Cells

Hybrid View

the_red_engine Remove Duplicates Function... 09-17-2016, 05:08 PM
shg Re: Remove Duplicates... 09-17-2016, 05:23 PM
sanram Re: Remove Duplicates... 09-17-2016, 05:32 PM
sanram Re: Remove Duplicates... 09-17-2016, 05:48 PM
the_red_engine Re: Remove Duplicates... 09-17-2016, 06:47 PM
shg Re: Remove Duplicates... 09-17-2016, 06:49 PM
sanram Re: Remove Duplicates... 09-17-2016, 06:51 PM
the_red_engine Re: Remove Duplicates... 09-17-2016, 07:20 PM
sanram Re: Remove Duplicates... 09-17-2016, 07:24 PM
the_red_engine Re: Remove Duplicates... 09-17-2016, 07:25 PM
the_red_engine Re: Remove Duplicates... 09-17-2016, 07:56 PM
sanram Re: Remove Duplicates... 09-17-2016, 08:01 PM
the_red_engine Re: Remove Duplicates... 09-17-2016, 08:10 PM
jeffreybrown Re: Remove Duplicates... 09-17-2016, 08:15 PM
sanram Re: Remove Duplicates... 09-17-2016, 08:19 PM
the_red_engine Re: Remove Duplicates... 09-17-2016, 08:20 PM
  1. #1
    Registered User
    Join Date
    08-20-2016
    Location
    California, USA
    MS-Off Ver
    2011
    Posts
    35

    Remove Duplicates Function for Single Cells

    I have numerous cells, each cell in the column contains duplicate values that I would like removed (duplicates to be removed from each individual cell, not from entire column).

    Example:

    Cell A1 contains: MX-30, MX-30, MX-30, MX-31, MX-32, result after function should be: MX-30, MX-31, MX-32.

    Cell A2 contains: MX-30, MX-30, MX-31, result after function should be: MX-30, MX-31.

    All of my values are separated by commas, so I just need a function/formula that I can copy and paste down across the entire column so that it will remove the duplicate values that appear inside of each cell.

    Thank you in advance for anyone that chimes in with a solution,

    Red Engine

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Remove Duplicates Function for Single Cells

    A
    B
    2
    MX-30, MX-30, MX-30, MX-31, MX-32
    3
    MX-30, MX-31, MX-32 A3: =TRE(A2)


    Function TRE(sInp As String) As String
      Dim asInp() As String
      
      asInp = Split(Replace(sInp, " ", ""), ",")
      DeDup asInp
      TRE = Join(asInp, ", ")
    End Function
    
    Function DeDup(av As Variant)
      ' shg 2012
    
      ' Removes duplicates in situ from the sorted dynamic array av
      Dim iLB           As Long   ' lower bound of av
      Dim iUB           As Long   ' upper bound of av
      Dim iW            As Long   ' write pointer
      Dim iR            As Long   ' read pointer
    
      iLB = LBound(av)
      iUB = UBound(av)
    
      iW = iLB
      iR = iW + 1
    
      Do While iR <= iUB
        If av(iW) <> av(iR) Then
          iW = iW + 1
          av(iW) = av(iR)
        End If
        iR = iR + 1
      Loop
    
      ReDim Preserve av(iLB To iW)
    End Function
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Remove Duplicates Function for Single Cells

    Do you know that maximum how many unique values will stay in a cell?

  4. #4
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Remove Duplicates Function for Single Cells

    If you want a VBA solution then you can use this :
    Function Remove_Dupli(Rng As Range) As String
        Dim strArray() As String
        Dim strColl As Collection
        Set strColl = New Collection
        strArray = Split(Rng, ",")
        On Error Resume Next
        For i = LBound(strArray) To UBound(strArray)
            strColl.Add Trim(strArray(i)), CStr(Trim(strArray(i)))
        Next i
        For i = 1 To strColl.Count
            If Result = "" Then
                Result = strColl(i)
            Else
                Result = Result & ", " & strColl(i)
            End If
        Next i
        Remove_Dupli = Result
    End Function
    Then write this formula on B1 :
    Remove_Dupli($A1)

  5. #5
    Registered User
    Join Date
    08-20-2016
    Location
    California, USA
    MS-Off Ver
    2011
    Posts
    35

    Re: Remove Duplicates Function for Single Cells

    There is no maximum unique values - each cell contains a different # of values, sometimes a cell may have up to 100 unique values after duplicates are removed. Thank you guys for writing in, I will try the above suggestions. Does anyone have something that I could paste into the adjacent cell though?

    For instance, if A1 contains: MX-30, MX-40, MX-30, MX-50, MX-60, is there something like an "=IF" formula I could paste into cell B1 to return: MX-30, MX-40, MX-50, MX-60? That way, I could just copy the formula down across the column to remove duplicates from the cells.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Remove Duplicates Function for Single Cells

    That's not going to happen without code (VBA).

  7. #7
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Remove Duplicates Function for Single Cells

    As you don't know the maximum unique values, so it is not possible with formula as far as I know. But may be an expert can give you the correct answer. Because sometimes they create some awesome array formulas to solve the problem like that. But my suggestion is to use the VBA instead.

  8. #8
    Registered User
    Join Date
    08-20-2016
    Location
    California, USA
    MS-Off Ver
    2011
    Posts
    35

    Re: Remove Duplicates Function for Single Cells

    Okay, so for the VBA I would inject that code into my VBA module section, then run it, then paste "Remove_Dupli($A1)" into B1 and copy it down onto all the cells that I need?

  9. #9
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Remove Duplicates Function for Single Cells

    Yes. That's all you need.

  10. #10
    Registered User
    Join Date
    08-20-2016
    Location
    California, USA
    MS-Off Ver
    2011
    Posts
    35

    Re: Remove Duplicates Function for Single Cells

    Thank you, I will give it a try.

  11. #11
    Registered User
    Join Date
    08-20-2016
    Location
    California, USA
    MS-Off Ver
    2011
    Posts
    35

    Re: Remove Duplicates Function for Single Cells

    I tried the VBA recommendation, input the VBA into the module section, saved and closed the window, then pasted "Remove_Dupli($A1)" into the B1, it doesn't execute any results, it only yields "#NAME!".

  12. #12
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Remove Duplicates Function for Single Cells

    May be you are doing something wrong. See the attachment.

    BTW you need to save your file with a macro-enabled format such as .xls or .xlsm
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    08-20-2016
    Location
    California, USA
    MS-Off Ver
    2011
    Posts
    35

    Re: Remove Duplicates Function for Single Cells

    Okay, I just got it to work and it executed perfectly, so thank you. I had a minor typo issue when I copied the VBA into the module. Thank you for the solution and thank you to everyone who wrote in with answers, this community is great and I sincerely appreciate the feedback on my post.

  14. #14
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Remove Duplicates Function for Single Cells

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    HTH
    Regards, Jeff

  15. #15
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Remove Duplicates Function for Single Cells

    You are welcome.

  16. #16
    Registered User
    Join Date
    08-20-2016
    Location
    California, USA
    MS-Off Ver
    2011
    Posts
    35

    Re: Remove Duplicates Function for Single Cells

    Marked as solved, thanks guys.

+ 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 word in single cell
    By iwanttoexcelinexcel in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-24-2015, 02:23 PM
  2. Remove duplicates function not removing duplicates
    By Berilium2 in forum Excel General
    Replies: 3
    Last Post: 04-01-2015, 06:55 AM
  3. [SOLVED] Remove duplicates from single cell
    By Petros Georgilas in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-19-2014, 02:58 PM
  4. Remove Duplicates and Multiple Rows into Single Cell with Commas.
    By bfitzpa in forum Access Tables & Databases
    Replies: 1
    Last Post: 06-05-2014, 07:42 AM
  5. [SOLVED] Remove duplicates in a single cell
    By SonGoku in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-27-2013, 06:35 AM
  6. Replies: 4
    Last Post: 06-06-2012, 02:15 PM
  7. remove entire row based on duplicates from single column
    By mikemeadeuk in forum Excel General
    Replies: 2
    Last Post: 10-15-2011, 02:57 PM

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