+ Reply to Thread
Results 1 to 8 of 8

Remove Duplicated from multiple column

Hybrid View

  1. #1
    Registered User
    Join Date
    11-04-2015
    Location
    London, england
    MS-Off Ver
    2007
    Posts
    60

    Remove Duplicated from multiple column

    I need to remove duplicate from two columns with a vba any ideas?
    Capture.JPG

    So bacically as you can see i want both colums to only have unique values

    I have tried
    ActiveSheet.Range("A:B").RemoveDuplicates Columns:=Array(1,2), Header:=xlYes
    but it did not work
    Attached Images Attached Images
    Last edited by shelim481; 02-20-2020 at 11:31 AM.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,346

    Re: Remove Duplicated from multiple column

    Sub Test()
        Dim i As Long
        For i = 2 To Cells(Rows.Count, "B").End(xlUp).Row
            If Cells(i, "A").Value = Cells(i, "B").Value Then Cells(i, "B").Clear
        Next i
        Range("B:B").SpecialCells(xlCellTypeBlanks).Delete
    End Sub
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    11-04-2015
    Location
    London, england
    MS-Off Ver
    2007
    Posts
    60

    Re: Remove Duplicated from multiple column

    If there is duplicated in column A this does not work as intended, any solutions, i think it was my mistake i showed the wrong numbers

  4. #4
    Valued Forum Contributor
    Join Date
    08-03-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2007, 2010, 2013, 2016, Office 365
    Posts
    492

    Re: Remove Duplicated from multiple column

    Hi

    that code will treat the 2 column values as "pairs" and will only remove a "repeated-pair"
    ..so what you are asking for is a loop that will remove any duplicate found in the 'selected' or 'specified' range-block.

    zeddy

  5. #5
    Valued Forum Contributor
    Join Date
    08-03-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2007, 2010, 2013, 2016, Office 365
    Posts
    492

    Re: Remove Duplicated from multiple column

    Hi

    Bernie's code will remove any cell in column B that is already in column A
    ..but it won't remove any duplicates that already exist in column A

    zeddy

  6. #6
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,767

    Re: Remove Duplicated from multiple column

    Sub RemoveDups()
    Dim cell As Range
    Dim DupFound As Range
    Application.ScreenUpdating = False
    For Each cell In Range("A1:A20")
        If cell.Value <> "" Then
            Set DupFound = Range("B:B").Find(cell.Value)
            On Error Resume Next
            If DupFound Then
                Cells(DupFound.Row, "B").Value = ""
            End If
            Set DupFound = Range("A" & (cell.Row + 1) & ":A20").Find(cell.Value)
            On Error Resume Next
            If DupFound Then
                Cells(DupFound.Row, "A").Value = ""
            End If
        End If
    Next cell
    Range("A:B").SpecialCells(xlCellTypeBlanks).Delete
    Application.ScreenUpdating = True
    End Sub
    edit: add second check for duplicates in col. A
    Last edited by KOKOSEK; 02-20-2020 at 11:37 AM.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  7. #7
    Valued Forum Contributor
    Join Date
    08-03-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2007, 2010, 2013, 2016, Office 365
    Posts
    492

    Re: Remove Duplicated from multiple column

    ..maybe just add this line to Bernie's code..
    ActiveSheet.[A:A].RemoveDuplicates Columns:=1, Header:=xlNo
    zeddy

  8. #8
    Registered User
    Join Date
    11-04-2015
    Location
    London, england
    MS-Off Ver
    2007
    Posts
    60

    Re: Remove Duplicated from multiple column

    Cool thank you all, much appreciated

+ 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 many unwanted/duplicated styles
    By Vaslo in forum Excel General
    Replies: 9
    Last Post: 11-24-2014, 12:54 AM
  2. Replies: 26
    Last Post: 07-29-2014, 06:38 PM
  3. Remove Duplicated items in combo box
    By FRIEL in forum Excel General
    Replies: 11
    Last Post: 12-03-2012, 04:26 PM
  4. Replies: 3
    Last Post: 09-11-2012, 02:19 AM
  5. Replies: 6
    Last Post: 03-26-2012, 05:12 PM
  6. Remove Combobox Duplicated items
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2009, 02:35 AM
  7. Remove ALL duplicated records, leaving behind NONE
    By Christopher Dawes in forum Excel General
    Replies: 2
    Last Post: 06-06-2005, 07:05 PM

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