+ Reply to Thread
Results 1 to 6 of 6

Matching two columns and copying the corresponding rows to a new sheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Matching two columns and copying the corresponding rows to a new sheet

    Hello,

    I am trying to Find on Sheet1 the mean Annual wages that matches the mean Annual wages on Sheet2.
    Once a match is found I would like that copied from Sheet 1 and pasted to the 3rd Sheet named "Matches".

    I've done some research and all I could find is a code that looks like this...

     Dim rng As Range
         Set rng = Range("C:C").Find(What:=ActiveCell.Value, _
             LookAt:=xlWhole, MatchCase:=False)
         If Not rng Is Nothing Then
             rng.Offset(0, 1).Select
         End If
    It doesn't really make sense but can anyone guide me in the right direction?

    Thank You!
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Matching two columns and copying the corresponding rows to a new sheet

    Try this:
    Sub x()
    
    Dim r As Range, r2 As Range
    
    For Each r In Sheet1.Range("B4", Sheet1.Range("B" & Rows.Count).End(xlUp))
        Set r2 = Sheet2.Range("B:B").Find(What:=r.Value, lookAt:=xlWhole, MatchCase:=False)
        If Not r2 Is Nothing Then
            r.EntireRow.Copy Sheet3.Range("A" & Rows.Count).End(xlUp)(2)
            Set r2 = Nothing
        End If
    Next r
    
    End Sub

  3. #3
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Matching two columns and copying the corresponding rows to a new sheet

    Thank you,

    What if I wanted to match the columns with the job description?
    How would I alter the code?

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Matching two columns and copying the corresponding rows to a new sheet

    I can tell you, but see if you can work it out. There's a loop through the first sheet which searches the second...

  5. #5
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Matching two columns and copying the corresponding rows to a new sheet

    Should I use a nested loop with the inst function?

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Matching two columns and copying the corresponding rows to a new sheet

    All you have to do is change the ranges in the code above that you are searching and comparing. There's no need to add anything new. I can't access your file now, so can't check the references.

+ 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. Matching data and copying row to different sheet
    By DanishDudeAU in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-29-2013, 04:59 AM
  2. [SOLVED] Copying data into new sheet depending upon selection of rows or columns
    By vickyyar in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-13-2012, 11:59 AM
  3. Copying rows from sheet where cells in specific columns are empty
    By wishmaker in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2010, 10:11 AM
  4. Replies: 3
    Last Post: 10-08-2009, 02:22 PM
  5. Matching one to many from one sheet to another, then copying
    By bluegnu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-10-2009, 06:49 AM

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