+ Reply to Thread
Results 1 to 7 of 7

Macro/VBA need help to copy the mathces to the master worksheet

  1. #1
    Registered User
    Join Date
    10-24-2013
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    20

    Question Macro/VBA need help to copy the mathces to the master worksheet

    Hello
    I found the below VBA code to find the matches, unfortunately, it copied to the wrong place. Instead I need the matches, copy its corresponding value to column D from "Data" worksheet to the "Master" worksheet. For example, in "Data" worksheet the Code ABC is 3534, it should then copy only the value to the "Master" worksheet's D column. Please help.

    Master worksheet
    A B C D E
    Code Orange Apple Total
    ABC 123.00 567.00 690.00
    DEF 57,974.34 - 57,974.34
    GHI 58,490.00 8.00 58,498.00
    MNO 4.00 571.00 575.00
    LOK 7,604.00 899.00 8,503.00
    MKO - - -
    MIL 1,674.00 - 1,674.00
    FRE 13,415.12 - 13,415.12

    Data worksheet
    Code Total
    ABC 3534
    DEF 12276
    GHI 3248
    IN0019 11726
    IN0020 1984
    LOK 55
    MIL 1472
    MNO 10384
    Grand Total 121047

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Macro/VBA need help to copy the mathces to the master worksheet

    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    10-24-2013
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Macro/VBA need help to copy the mathces to the master worksheet

    Thank you, Tinbendr. It works.

    Can I ask one more question? For those not match, if there anyway to insert to the end of the code in the master worksheet?

    Code Orange Apple Total
    ABC 123.00 567.00 690.00
    DEF 57,974.34 - 57,974.34
    GHI 58,490.00 8.00 58,498.00
    MNO 4.00 571.00 575.00
    LOK 7,604.00 899.00 8,503.00
    MKO - - -
    MIL 1,674.00 - 1,674.00
    FRE 13,415.12 - 13,415.12
    IN0019 - - 11726.00 11726.00
    IN0020 - - 1984.00 1984.44.00
    EEE - - 9876.00 9876.00


    Data worksheet
    Code Total
    ABC 3534
    DEF 12276
    GHI 3248
    IN0019 11726
    IN0020 1984

    LOK 55
    MIL 1472
    MNO 10384
    EEE 9876
    Grand Total 121047
    Last edited by maytam; 03-14-2014 at 01:39 AM.

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Macro/VBA need help to copy the mathces to the master worksheet

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-24-2013
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Macro/VBA need help to copy the mathces to the master worksheet

    Dear Tinbendr

    It doesn't work. It now first copy those matches to the E column, then it copy all the data (both match and not match) in "Data" sheet to the "Master" sheet. Therefore, those matches are repeated in the "Master" sheet.

    Instead, the VBA needs to

    First find the matches
    then copy its correspongding value to the column E from "Data" to "Master"
    since those matches also have "Orange" amount in D column that should be
    retained, say the code "ABC" have both "Orange" and "Apple" amount,
    B D E F
    Code Orange Apple Total
    ABC 123.00 567.00 690.00
    DEF 57,974.34 - 57,974.34
    GHI 58,490.00 8.00 58,498.00

    Else only for those not match
    it should be inserted to the end of the code with its value to the column B and
    E respectively to the "Master" sheet, say the code "IN0019" is not existed in
    "Master" but existed in "Data" so it should insert the code "IN0019"
    and its value "11,726.00" to B and E column to the "Master" sheet. The result
    should look like below
    B D E F
    Code Orange Apple Total
    ABC 123.00 567.00 690.00
    DEF 57,974.34 - 57,974.34
    GHI 58,490.00 8.00 58,498.00
    IN0019 - 11,726.00 11,726.00
    Last edited by maytam; 03-16-2014 at 10:36 PM.

  6. #6
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Macro/VBA need help to copy the mathces to the master worksheet

    Oops, sorry.

    Correct these lines in the lower half.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-24-2013
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Macro/VBA need help to copy the mathces to the master worksheet

    Thank you. That code worked great. I appreciate your help.

    Cheers,

+ 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. Replies: 9
    Last Post: 01-16-2014, 11:28 AM
  2. Replies: 3
    Last Post: 02-04-2013, 06:00 PM
  3. Drop Down List to Copy Entire Contents of Worksheet into Master Worksheet
    By mrmartin in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-14-2011, 10:54 PM
  4. Macro to copy data from worksheet (name changes daily) to master workbook
    By bshelman in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-10-2008, 08:52 AM
  5. Copy an existing worksheet and carry totals to a master worksheet
    By adore_r in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2008, 12:02 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