Results 1 to 1 of 1

VBA - Copy row from workbook1 to workbook2 based on string matching

Threaded View

  1. #1
    Registered User
    Join Date
    08-09-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1

    VBA - Copy row from workbook1 to workbook2 based on string matching

    Hello,

    Let me start of by saying that I know nothing about VBA. I have some Java experience, but VBA looks crazy to me. I have tried to modify others code, but I obviously don't understand VBA syntax well enough (which means not at all ). Here is what I need to do:

    Basically I want a macro(in Excel 2010) that will loop through each ID in workbook2, and find it in workbook1, and copy all the data (only columns B-E) from workbook 1 to workbook 2, and repeat, until there are no more id's in workbook2. If the id can't be found in workbook1, then leave the row blank in workbook2 and move on. I was thinking something like this:

    for(int i = 2; curentCell.isEmpty() == false; i++)
    {
    for(int j = 2; currentCell.isEmpty() == false; j++)
    {
    if(workbook2.sheet2.colA.row[i] == workbook1.sheet1.colA.row[j])
    {
    CopyData from workbook1.sheet1.row[j].col(B-E)
    to
    workbook2.sheet2.row[i].col(B-E)
    }
    }
    } Workbook1>Sheet1
    A B C D E F
    ID data1 data2 data3 data4 data5
    1 58 27 48 10 38
    2 78 809 34 34 433
    3 78 980 123 3421 12
    4 345 432 23 54 1

    Workbook2>Sheet2
    A B C D E F
    ID data1 data2 data3 data4 data5
    1
    3
    6

    Desired Result
    Workbook2>Sheet2 (after macro has run)
    A B C D E F
    ID data1 data2 data3 data4 data5
    1 58 27 48 10
    3 78 809 34 34
    6

    What do you guys think?

    Thanks!!
    Last edited by Cutter; 08-09-2012 at 03:48 PM. Reason: Added code tags

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