+ Reply to Thread
Results 1 to 8 of 8

Complicated Duplicate Issue

Hybrid View

  1. #1
    Registered User
    Join Date
    07-30-2007
    Posts
    61

    Question Complicated Duplicate Issue

    Hi

    This is tricky, but I hope there is a way of doing this

    I will simplify the problem to help.

    I have 2 columns, A and B
    A is ID1
    B is ID2

    How can I work out if there are duplicate ID2s pointing at the same LE ID without doing filters, so basically if there are more than 1 ID2s pointing to 1 ID1?

    Another spanner is the works is that an ID1 can have more than 1 ID2.

    Mini file attached which should help with my explanation

    Kind regards

    Keith
    Last edited by roasty_1; 04-23-2008 at 11:56 AM.

  2. #2
    Forum Contributor Portuga's Avatar
    Join Date
    02-20-2004
    Location
    Portugal
    MS-Off Ver
    365
    Posts
    852
    Hi,

    Your file is not attached.
    If you found the solution to your question. Mark the thread as "Solved"
    Thank everyone that helped you with a valid solution by clicking on their

    There is no such thing as a problem, only a temporary lack of a solution

  3. #3
    Registered User
    Join Date
    07-30-2007
    Posts
    61

    Smile file attached

    file now attached

    thanks
    Attached Files Attached Files

  4. #4
    Forum Contributor Portuga's Avatar
    Join Date
    02-20-2004
    Location
    Portugal
    MS-Off Ver
    365
    Posts
    852
    Hi,

    The obvious choice would be the advanced filter. Choose both columns and then filter by unique entries.
    Or

    the code bellow will flag duplicate entries in red:
    (www.techonthenet.com)


    Sub TestForDups()
    
        Dim LLoop As Integer
        Dim LTestLoop As Integer
        Dim LClearRange As String
    
        Dim Lrows As Integer
        Dim LRange As String
    
        'Column A values
        Dim LChangedValue As String
        Dim LTestValue As String
    
        'Column B values
        Dim LChangedValueB As String
        Dim LTestValueB As String
    
        'Test first 200 rows in spreadsheet for uniqueness
        Lrows = 200
        LLoop = 2
    
        'Clear all flags
        LClearRange = "A2:B" & Lrows
        Range(LClearRange).Interior.ColorIndex = xlNone
    
        'Check first 200 rows in spreadsheet
        While LLoop <= Lrows
            LChangedValue = "A" & CStr(LLoop)
            LChangedValueB = "B" & CStr(LLoop)
    
            If Len(Range(LChangedValue).Value) > 0 Then
    
                'Test each value for uniqueness
                LTestLoop = 2
                While LTestLoop <= Lrows
                    If LLoop <> LTestLoop Then
                        LTestValue = "A" & CStr(LTestLoop)
                        LTestValueB = "B" & CStr(LTestLoop)
                        'Value has been duplicated in another cell
                        If (Range(LChangedValue).Value = Range(LTestValue).Value) And (Range(LChangedValueB).Value = Range(LTestValueB).Value) Then
                            'Set the background color to red in column A
                            Range(LChangedValue).Interior.ColorIndex = 3
                            Range(LTestValue).Interior.ColorIndex = 3
    
                            'Set the background color to red in column B
                            Range(LChangedValueB).Interior.ColorIndex = 3
                            Range(LTestValueB).Interior.ColorIndex = 3
    
                        End If
    
                    End If
    
                    LTestLoop = LTestLoop + 1
                Wend
    
            End If
    
            LLoop = LLoop + 1
        Wend
    
    End Sub

  5. #5
    Registered User
    Join Date
    07-30-2007
    Posts
    61

    Question duplicate formula

    Not really what I wanted, but thanks, it is much more complicated than an advanced filter

    The criteria is as follows

    ID1 is linked to one+ ID2's, no single ID2 can be linked to the same ID1 more than once, but an ID2 can be linked to two different ID1's, for example

    ID1 ID2 RESULT
    1 A DUPLICATE
    1 A DUPLICATE
    1 A DUPLICATE
    2 B NOT A DUPLICATE
    2 C NOT A DUPLICATE
    3 C NOT A DUPLICATE
    4 D DUPLICATE
    4 D DUPLICATE

    Is there there away to automate this as I have a huge data set to apply this to so manual checks is out of the question

    If anyone can help please help

  6. #6
    Registered User
    Join Date
    07-30-2007
    Posts
    61

    Thumbs up

    Hi Portuga

    Thanks for the code, it works spot on, I didnt quite get it right from you reply but it I managed to get it right. Thanks again, great help.

    Keith

  7. #7
    Registered User
    Join Date
    07-30-2007
    Posts
    61

    Smile

    Quote Originally Posted by Portuga
    Hi,

    The obvious choice would be the advanced filter. Choose both columns and then filter by unique entries.
    Or

    the code bellow will flag duplicate entries in red:
    (www.techonthenet.com)


    Sub TestForDups()
    
        Dim LLoop As Integer
        Dim LTestLoop As Integer
        Dim LClearRange As String
    
        Dim Lrows As Integer
        Dim LRange As String
    
        'Column A values
        Dim LChangedValue As String
        Dim LTestValue As String
    
        'Column B values
        Dim LChangedValueB As String
        Dim LTestValueB As String
    
        'Test first 200 rows in spreadsheet for uniqueness
        Lrows = 200
        LLoop = 2
    
        'Clear all flags
        LClearRange = "A2:B" & Lrows
        Range(LClearRange).Interior.ColorIndex = xlNone
    
        'Check first 200 rows in spreadsheet
        While LLoop <= Lrows
            LChangedValue = "A" & CStr(LLoop)
            LChangedValueB = "B" & CStr(LLoop)
    
            If Len(Range(LChangedValue).Value) > 0 Then
    
                'Test each value for uniqueness
                LTestLoop = 2
                While LTestLoop <= Lrows
                    If LLoop <> LTestLoop Then
                        LTestValue = "A" & CStr(LTestLoop)
                        LTestValueB = "B" & CStr(LTestLoop)
                        'Value has been duplicated in another cell
                        If (Range(LChangedValue).Value = Range(LTestValue).Value) And (Range(LChangedValueB).Value = Range(LTestValueB).Value) Then
                            'Set the background color to red in column A
                            Range(LChangedValue).Interior.ColorIndex = 3
                            Range(LTestValue).Interior.ColorIndex = 3
    
                            'Set the background color to red in column B
                            Range(LChangedValueB).Interior.ColorIndex = 3
                            Range(LTestValueB).Interior.ColorIndex = 3
    
                        End If
    
                    End If
    
                    LTestLoop = LTestLoop + 1
                Wend
    
            End If
    
            LLoop = LLoop + 1
        Wend
    
    End Sub
    This code works spot on, however I need to run this code over 30000 rows, it takes hours to calculate. Is there a way to split the code so it only highlights the 1st 5000 cells that are duplicates but still looking at the whole range?

    Thanks

  8. #8
    Banned User!
    Join Date
    10-14-2006
    Posts
    1,211
    Quote Originally Posted by roasty_1
    file now attached

    thanks
    =IF(AND(COUNTIF($A$2:$A$27,A2)>1,COUNTIF($B$2:$B$27,B2)>1),"dup","")
    Attached Files Attached Files

+ 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