+ Reply to Thread
Results 1 to 3 of 3

Find matching data in 2 worksheets and copy to 3rd

Hybrid View

Frick Find matching data in 2... 01-30-2025, 12:39 PM
dangelor Re: Find matching data in 2... 01-30-2025, 02:54 PM
Sintek Re: Find matching data in 2... 01-31-2025, 06:18 AM
  1. #1
    Forum Contributor
    Join Date
    12-14-2005
    Location
    US
    MS-Off Ver
    Excel 2019, Excel 365, Excel Mobile (Android)
    Posts
    193

    Find matching data in 2 worksheets and copy to 3rd

    I have 2 data worksheets each with over 2000 rows. What I would like to do is enter a criteria, and then search the 2 data worksheets and look for matches. Then copy those matches to a 3rd worksheets named DATA 3.

    I have attached 2 worksheets for reference. DATA 1 and DATA 2 have data. For example, I want to search DATA 1 & 2 looking for Document ID matches. In DATA 1 the Document ID is column A and in DATA 2 the Document ID is Column F. The search would look for the matches in both worksheets and list the resulting matches in a new worksheet named DATA 3.

    Ideally, it would be good if I can just list the column name that I am looking for matches and get the results (for example. Document ID or Name, etc)

    Thanks for all help offered.
    Attached Files Attached Files

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,312

    Re: Find matching data in 2 worksheets and copy to 3rd

    Possibly...
    Option Explicit
    Sub Search_Copy()
        Dim d1 As Variant, d2 As Variant
        Dim ws As Worksheet
        Dim i As Long, j As Long, lRow As Long
        
        Set ws = Workbooks.Add.Sheets(1)
        Workbooks("Data 1.xlsx").Worksheets("Sheet1").Rows(1).Copy ws.Rows(1)
            
        'change workbook and worksheet names as needed.
        d1 = Workbooks("Data 1.xlsx").Worksheets("Sheet1").Cells(1, 1).CurrentRegion
        d2 = Workbooks("Data 2.xlsx").Worksheets("Sheet1").Cells(1, 1).CurrentRegion
        
        For i = 2 To UBound(d1)
            For j = 2 To UBound(d2)
                If d1(i, 1) = d2(j, 6) Then
                    With ws
                        lRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
                        Workbooks("Data 1.xlsx").Worksheets("Sheet1").Rows(i).Copy .Rows(lRow + 1)
                    End With
                End If
            Next j
        Next i
    End Sub

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Find matching data in 2 worksheets and copy to 3rd

    attached 2 worksheets
    2 workbooks you mean
    new worksheet named DATA 3.
    new workbook you mean or already existing workbook 3
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

+ 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. VBA to find matching cell value from 2 workbooks then copy data from one to the other
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-14-2021, 06:48 PM
  2. Find matching data and copy adjacent cell
    By Northernpig in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-02-2014, 03:28 PM
  3. Find matching data and copy adjacent cell
    By Northernpig in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-02-2014, 03:18 PM
  4. Need VBA to find matching data between worksheets & copy adjacent rows.
    By Helen62 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-16-2013, 12:19 AM
  5. copy matching data between worksheets using macro???
    By mixel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-27-2007, 06:54 PM
  6. how to copy matching data between worksheets
    By mixel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2007, 10:04 PM
  7. [SOLVED] How do I compare data in two worksheets to find matching cells?
    By Gary in forum Excel General
    Replies: 4
    Last Post: 03-02-2006, 05:10 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