+ Reply to Thread
Results 1 to 3 of 3

Macro to remove duplicate values from cell

  1. #1
    Registered User
    Join Date
    03-06-2013
    Location
    Prague
    MS-Off Ver
    M365, version 2304
    Posts
    40

    Macro to remove duplicate values from cell

    Hi all

    I have a worksheet where, in one of the columns, we need to remove any duplicate values. The values are separated by a ;

    At the moment, I have found the following:

    PHP Code: 
    Sub RemoveDupesInCell()

    Dim dic As Objectcell As Rangetemp As Variant
    Dim i 
    As Long
    Set dic 
    CreateObject("scripting.dictionary")
    With dic
        
    For Each cell In Range("BB1:BB" Cells(Rows.Count"BB").End(xlUp).Row)
            .
    RemoveAll
            
    If Len(cell.Value) > 0 Then
                temp 
    Split(" " cell.Value";")
                For 
    0 To UBound(temp)
                    If 
    Not .Exists(temp(i)) Then .Add temp(i), temp(i)
                
    Next i
                cell
    .Value Mid(Join(.Keys";"), 2)
            
    End If
        
    Next cell
    End With
    End Sub 
    This is mostly working, except where a duplicate value exists at the beginning of the cell, and is not preceded by a ;.

    So, if I have:

    duplicate;duplicate;duplicate;duplicate

    it will turn into

    duplicate;duplicate

    If I have:

    duplicate;duplicate

    it remains the same.

    Does anybody know what I am missing in this?

    Thanks!!

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Macro to remove duplicate values from cell

    Try

    Please Login or Register  to view this content.
    so everything has a semicolon both before and after.
    Martin

  3. #3
    Registered User
    Join Date
    03-06-2013
    Location
    Prague
    MS-Off Ver
    M365, version 2304
    Posts
    40

    Re: Macro to remove duplicate values from cell

    That is perfect! Thank you so much for replying so quickly! I have made a small donation to the charity you mention (sorry - I can't send GiftAid, as I'm not a UK resident).

+ 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. [SOLVED] How to sum duplicate values then remove the duplicate rows?
    By terry3218 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 12-12-2015, 02:38 AM
  2. [HELP] me to remove duplicate values and leave that cell as blank
    By spa3212 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-30-2015, 01:23 PM
  3. [HELP] me to remove duplicate values and leave that cell as blank
    By spa3212 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-30-2015, 12:55 AM
  4. Formula or code to remove duplicate text or values within a cell
    By winmaxservices1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-22-2014, 06:16 AM
  5. Macro to remove duplicate text within a cell
    By abramo in forum Excel Programming / VBA / Macros
    Replies: 37
    Last Post: 09-27-2013, 02:28 AM
  6. excel macro to remove specific columns and rows + remove duplicate
    By garrywelson in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-17-2013, 12:03 PM
  7. Excel 2007 : Remove Duplicate Values from top 5
    By loknath in forum Excel General
    Replies: 1
    Last Post: 11-08-2011, 09:46 AM

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