+ Reply to Thread
Results 1 to 6 of 6

Match Two Columns on Two Different Sheets, Then Copy Row, Otherwise Move to Next Row

  1. #1
    Registered User
    Join Date
    07-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Match Two Columns on Two Different Sheets, Then Copy Row, Otherwise Move to Next Row

    Hi Everybody,

    I am trying to match two column of cells on two different sheets, if they match, it should copy the entire row to sheet2.

    So, if A2:sheet1 = A2:sheet2, then copy the date in sheet1:a2 to sheet 2:a2 (and fill in the rest of the row). Otherwise, move to the next row.

    I guess I'm having problems because I can't figure out how to scan the entire column for a matching stock symbol. The rows may or may not match, but that doesn't mean an exact match doesn't exist.

    In the example I attached, AAWW is in the 7th row in sheet 1, but in the 8th row on sheet2. (I want the data on sheet 1 to be moved to sheet 2). They wouldn't match up exactly when going row-by-row, but that doesn't mean there isn't an AAWW match to be made. Likewise ABCO is in 12th row in sheet 1, but in the 9th row on sheet 2. So, I'm stuck on trying to figure out how to get the data from sheet 1 to sheet 2.

    My solution isn't smart enough to know the matching symbol are really available in the column somewhere.

    I attached an example of what I am trying to do. Any suggestions (or code samples) would be greatly appreciated.

    Thanks
    Attached Files Attached Files
    Last edited by wallstcheater; 07-11-2012 at 12:07 AM. Reason: Solved!!

  2. #2
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: Match Two Columns on Two Different Sheets, Then Copy Row, Otherwise Move to Next Row

    I think what you actually want is somewhat different from what you've said you want.

    Here's what I think you want:

    1) Sheet2!A2 should find the matching element in Sheet!A:A, whichever row it's in.

    2) Sheet2!B2:H2 should copy across the corresponding columns from the matched row.

    Anyway I just smacked it with the reliable one-two punch of INDEX(MATCH()). See attached for what I mean.

    Also this is just my opinion but I would push sheet1!B:B through a VLOOKUP(C, build_a_table) rather than that big nest of IFs.
    Attached Files Attached Files

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Match Two Columns on Two Different Sheets, Then Copy Row, Otherwise Move to Next Row

    1. Create a named range "SheetOne" and refer it to:
    Please Login or Register  to view this content.
    2. In cell Sheet2,B1 enter:
    Please Login or Register  to view this content.
    Drag across to column H, and down to the end of the list
    Attached Files Attached Files
    Ben Van Johnson

  4. #4
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Match Two Columns on Two Different Sheets, Then Copy Row, Otherwise Move to Next Row

    wallstcheater,

    Welcome to the Excel Forum.


    Detach/open workbook MatchData w1 colA moverowonmatch w2 colA - wallstcheater - EF844253 - SDG10.xls and run the MatchData macro.



    If you want to use the macro on another workbook:


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


    Please Login or Register  to view this content.

    Then run the MatchData macro.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  5. #5
    Registered User
    Join Date
    07-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Match Two Columns on Two Different Sheets, Then Copy Row, Otherwise Move to Next Row

    Holy Cow, I tried Stanley's approach and it worked on the first try! I love you guys.

    Thank you very much!

  6. #6
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Match Two Columns on Two Different Sheets, Then Copy Row, Otherwise Move to Next Row

    wallstcheater,

    Thanks for the feedback.

    You are very welcome. Glad we could help.

    Come back anytime.

+ 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