+ Reply to Thread
Results 1 to 4 of 4

removing duplicates in list macro needed

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    removing duplicates in list macro needed

    Is it possible to remove duplicates from a range of cells? Via macro! I.e. if a document contains a list of names and data, and name appears more than once, delete than name and the associated data coluns to the right and left?

    All the best Alan
    Last edited by ad9051; 06-20-2011 at 01:18 PM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: removing duplicates in list macro needed

    Alan,

    Give this a try:
    Sub DeleteDuplicatesMacro_for_ad9051()
        
        Const NamesCol As String = "A"
        Const StartRow As Long = 2
        
        Dim rngDuplicates As Range: Set rngDuplicates = Nothing
        Dim RowIndex As Long
        
        For RowIndex = Range(NamesCol & Rows.Count).End(xlUp).Row To StartRow + 1 Step -1
            If WorksheetFunction.CountIf(Range(NamesCol & StartRow, NamesCol & RowIndex - 1), Range(NamesCol & RowIndex)) > 0 Then
                If rngDuplicates Is Nothing Then
                    Set rngDuplicates = Range(NamesCol & RowIndex)
                Else
                    Set rngDuplicates = Application.Union(rngDuplicates, Range(NamesCol & RowIndex))
                End If
            End If
        Next RowIndex
        
        If Not rngDuplicates Is Nothing Then rngDuplicates.EntireRow.Delete xlShiftUp
        
    End Sub


    Hope that helps,
    ~tigeravatar

  3. #3
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: removing duplicates in list macro needed

    I am a big fan of tiger avatar, ill give it a whirl! Cheers Alan

  4. #4
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: removing duplicates in list macro needed

    Works many thanks Alan

+ 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