+ Reply to Thread
Results 1 to 3 of 3

Thread: Can vba code identify duplicates numbers in a column via a message window?

  1. #1
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Office 2007
    Posts
    316

    Can vba code identify duplicates numbers in a column via a message window?

    Hello group! In a earlier post I had sought help trying to delete any duplicate info if there was a duplicate number in column V and have it delete the last entry row. With help from this site I was able to get that to work. The problem that I've since discovered is that I need to really look at the duplicate numbers to see what row of the duplicates that I would prefer to keep before deleting any of them; due to content entry if slightly different, etc. Thus my new request for help!

    What I'd like to do is have help with the following code or new code if possible which will allow me to identify the duplicate numbers in column "V" and have them appear in a message window. The code would search the entire column of data and afterwards pop up a message window that would say something to the effect "The following complaint #'s have duplicate entries: 454,462,527,..." etc.
    Then I would be able to manually filter those numbers and delete the row(s) I choose.

    The following code currently identifies the number of duplicate entries in column "V" and deletes the 2nd entry in Column "V" only (not the entire row). Afterwards a message window will appear notifying me something to the effect "There were 10 duplicate entries deleted". Would anyone be able to help modify this code to just identify the duplicate entry numbers instead of deleting anything?
    Any help would be appreciated.

    Sub DeleteDuplicateEntries()
       Dim rClMain As Range
       Dim rClDupe As Range
       Dim rCheck
       Dim N As Long
       Dim LR As Long, i As Long, found As Range
       Application.ScreenUpdating = False
       N = 0
           'currently starts in A6 down,adjust to your data
       Set rCheck = Range(Cells(6, 22), Cells(Rows.Count, 22).End(xlUp))
       For Each rClMain In rCheck
            '1st loop - (to speed things up ignore any empty cells)
           If rClMain <> Empty Then
               For Each rClDupe In rCheck
                    '2nd loop - compare non-empty rClDupe values
                    'and clear contents if it's a duplicated value
                   If rClDupe <> Empty And _
                   rClDupe.Value = rClMain.Value And _
                   rClDupe.address <> rClMain.address Then
                       rClDupe.ClearContents
                       N = N + 1
                   End If
               Next rClDupe
           End If
       Next
       Application.ScreenUpdating = True
       MsgBox "There were " & N & " duplicated entries deleted"
    End Sub
    Last edited by lilsnoop; 01-27-2012 at 06:51 AM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    MSO2007 on WinXP/MSO2000 on Win7/winXP
    Posts
    2,180

    Re: Can vba code identify duplicates numbers in a column via a message window?

    Maybe:
    Option Explicit
    Sub DeleteDuplicateEntries()
        Dim rClMain As Range
        Dim rClDupe As Range
        Dim rCheck
        Dim N As Long
        Dim LR As Long, i As Long, found As Range
        Application.ScreenUpdating = False
        N = 0
        'currently starts in A6 down,adjust to your data
        Set rCheck = Range(Cells(6, 22), Cells(Rows.Count, 22).End(xlUp))
        For Each rClMain In rCheck
            '1st loop - (to speed things up ignore any empty cells)
            If rClMain <> Empty Then
                For Each rClDupe In rCheck
                    '2nd loop - compare non-empty rClDupe values
                    'and clear contents if it's a duplicated value
                    
                    If rClDupe <> Empty And _
                        rClDupe.Value = rClMain.Value And _
                        rClDupe.Address <> rClMain.Address Then
                            'rClDupe.ClearContents
                            
                            Dim SummaryList As String
                            SummaryList = SummaryList & rClDupe.Value & vbTab & rClDupe.Address(0, 0) & vbCrLf
                            
                            
                            N = N + 1
                    End If
                Next rClDupe
            End If
        Next rClMain
        
        Application.ScreenUpdating = True
        MsgBox "There were " & N & " duplicated entries found" & vbCrLf & SummaryList
    End Sub
    ---
    Ben Van Johnson

  3. #3
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Office 2007
    Posts
    316

    Re: Can vba code identify duplicates numbers in a column via a message window?

    Thanks so much protonLeah! Your revision worked perfectly!

+ 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.2.0