+ Reply to Thread
Results 1 to 9 of 9

Fastest way to find a duplicate value in two large columns

Hybrid View

ArnolddG Fastest way to find a... 06-27-2014, 02:33 PM
Tsjallie Re: Fastest way to find a... 06-27-2014, 02:57 PM
ArnolddG Re: Fastest way to find a... 06-27-2014, 03:15 PM
Tsjallie Re: Fastest way to find a... 06-27-2014, 04:16 PM
ArnolddG Re: Fastest way to find a... 06-27-2014, 04:24 PM
Miraun Re: Fastest way to find a... 06-27-2014, 04:25 PM
Tsjallie Re: Fastest way to find a... 06-27-2014, 04:58 PM
ArnolddG Re: Fastest way to find a... 06-27-2014, 05:06 PM
Tsjallie Re: Fastest way to find a... 06-28-2014, 05:05 AM
  1. #1
    Forum Contributor
    Join Date
    12-07-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2021
    Posts
    126

    Fastest way to find a duplicate value in two large columns

    Hi,

    I need a comparison of values between two columns (10000 and 25000 rows)
    I my case there will be one duplicate max.

    I tried this with the Find function, but this still seems rather slow.

    Sub Select_Duplicate_cells()
        Dim Rng As Range
        Dim I As Long
        Dim oCell As Range
        For Each oCell In Range("TableA[Col A]").Cells
            With Range("TableB[Col B]")
                Set Rng = .Find(What:=oCell.Value, _
                                After:=.Cells(.Cells.Count), _
                                LookIn:=xlFormulas, _
                                LookAt:=xlWhole, _
                                SearchOrder:=xlByRows, _
                                SearchDirection:=xlNext, _
                                MatchCase:=False)
                If Not Rng Is Nothing Then
                    Debug.Print "Found! " & Rng.Address(False, False)
                    Exit Sub
                End If
            End With
        Next oCell
    End Sub
    What would be the fasted way to compare the values and select the duplicate (so the Conditional Formatting solution does not work for me)?

  2. #2
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Fastest way to find a duplicate value in two large columns

    Did you consider using Match function iso Find?
    Cheers!
    Tsjallie




    --------
    If your problem is solved, pls mark the thread SOLVED (see Thread Tools in the menu above). Thank you!

    If you think design is an expensive waste of time, try doing without ...

  3. #3
    Forum Contributor
    Join Date
    12-07-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2021
    Posts
    126

    Re: Fastest way to find a duplicate value in two large columns

    No I have actually never used Match.
    I see it is a worksheetfunction.
    Do you have any idea how I would have to use this in this case?

  4. #4
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Fastest way to find a duplicate value in two large columns

    Can you upload (a part of) your workbook?
    Saves me the pain of generating enough test data

  5. #5
    Forum Contributor
    Join Date
    12-07-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2021
    Posts
    126

    Re: Fastest way to find a duplicate value in two large columns

    I uploaded a test file.
    I would like to retreive a cell reference from Col A where there is a match with values in Col B

    Thanks for helping me out here...

    Compare values in two columns.xlsb

  6. #6
    Valued Forum Contributor Miraun's Avatar
    Join Date
    04-03-2009
    Location
    New England
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    554

    Re: Fastest way to find a duplicate value in two large columns

    You can always do a countif(A1,B1:$B$2000000000), and then apply an auto-filter, and see where you have hits.
    Going for Guru! Click the Star to the bottom left of this post if I helped!

  7. #7
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Fastest way to find a duplicate value in two large columns

    You could replace the part between with/end with by
            If Not IsError(Application.Match(oCell, Range("TableB[Col B]"), 0)) Then
                Rec = Application.Match(oCell, Range("TableB[Col B]"), 0)
                Debug.Print "Found! " & Range("TableB[Col B]").Cells(Rec, 1).Address
                Exit Sub
            End If
    It's somewhat faster when the duplicate is further away from the top. But not very much.
    By the way, this finds only the first duplicate. Your example contains two duplicates.

  8. #8
    Forum Contributor
    Join Date
    12-07-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2021
    Posts
    126

    Re: Fastest way to find a duplicate value in two large columns

    Wow! What a huge difference !

    With Find it takes 67 sec to find a match on row 6000
    With your changes using Match it takes about 4 sec.

    Btw, the double value was because of the testing, but I only need one match on a duplicate.

    You've been a great help

    Thanks very much !

  9. #9
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Fastest way to find a duplicate value in two large columns

    Nice to hear that

+ 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] fastest way to consolidate large data
    By jdlc in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-20-2014, 04:08 PM
  2. how to find duplicate cells in large array of numbers
    By DaveB in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 09-06-2005, 05:05 PM
  3. Fastest way to load large listbox
    By Peter Hill in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-22-2005, 03:38 AM
  4. Fastest way to sort large 2-D arrays?
    By RB Smissaert in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 02-07-2005, 08:08 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