+ Reply to Thread
Results 1 to 12 of 12

match data, then copy

Hybrid View

  1. #1
    Registered User
    Join Date
    03-26-2004
    Location
    Calif, USA
    Posts
    7

    match data, then copy

    Hello Experts,

    I hope this is quite simple for you vba experts but I'm a very beginner so please help!

    I have 2 worksheets: sheet-A and sheet-B.
    Please how do I:

    1. match the part# from sheetA (col B) with part# from sheetB (col A), then
    2. if a matching part# is found, copy the qty of the matched part# from sheetA to the qty field of the matching part# in sheet-A.
    3. Do loop

    I attach an img for more illustration of the above.

    Many many thanks in advance.
    N.
    Attached Images Attached Images

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Do you have a particular requirement that it must be a macro when you could achieve the result using Functions?


    rylo

  3. #3
    Registered User
    Join Date
    03-26-2004
    Location
    Calif, USA
    Posts
    7
    Hello Rylo,

    So glad to see your msg!
    Yes, I do need vba because the sheetB with the destination qty col is actually a big sheet with 1200 lines.
    sheetA, however, has about 50 lines for the products that customer orders.
    Then, what I try to do is, if the part# match, the qty should be copied to the qty field of sheetB on the row that has that particular part#. A brief illustration below:

    sheetA
    part# qty
    xxx102 2

    sheetB (before macro)
    part# qty
    xxx102 (blank)

    sheetB (after macro, part# xxx102 matches)
    part# qty
    xxx102 2

    I really really do hope you/others can help me with this vba code.

    N.
    Last edited by Nee; 11-08-2007 at 09:07 PM.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    You can achieve that result without VB code.
    Spreadsheet functions are much faster than VB code and are prefered unless there is an overiding reason not to.

    In your case, putting =SUMIF(SheetA!B:B,A2,SheetA!A:A) in SheetB C2 and using fill down to fill the rest of column C will get the result you desire.

  5. #5
    Registered User
    Join Date
    03-26-2004
    Location
    Calif, USA
    Posts
    7
    Mike,

    Pls look at the img I attached earlier. I do really need vba:

    1. You're right - I have an overiding reason not to be able to use the formula sumif

    2. the destination "qty" col in sheetA consists of merged cell, while the qty col from sheetB has single cell for each qty.

    thats why I need vba code badly for this case. I can see now it is a challenge and very interested in knowing if vba can do something for this.

    Many thanks to you and others for any hint in helping me with this roadblock.

    N.

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Not really obvious from the image that there are merged cells involved.

    Can you zip up an example workbook showing both sheets and explaining what should go where so we can review.


    rylo

+ 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