+ Reply to Thread
Results 1 to 7 of 7

merge two worksheets

  1. #1
    Registered User
    Join Date
    05-06-2009
    Location
    Florida, USA
    MS-Off Ver
    Excel 2003
    Posts
    6

    merge two worksheets

    I have two worksheets, one is called "donors" and the other "donations". On the "donors" worksheet, I have a list of people who have donated money to our organization, each person with a unique donor ID number.

    On the "donations" worksheet, it's just a list of all donations made along with the unique donor ID next to each donation. This list has alot of duplicate ID's, since for example one person can give 10 times in one year.

    I am building a macro which will use a nested loop to first look up an ID in the "donors" sheet, then go to the "donations" sheet and loop through all the rows, looking for that ID. If it finds a match, it will copy two cells from that row, and then paste them to the end of the row on the "donors" sheet. It will continue looping through all donations, looking for additional matches, and if it finds any will repeat the same actions. After it finishes this, it moves on to the next "donors" ID.

    I have some of the programming down, and I've confirmed that the nested loop functions as is, but I just don't know how to get it to copy and paste the cells from one sheet to the end of the row on the other sheet.

    Here is the code I have so far:

    Please Login or Register  to view this content.
    Can anyone help me finish this one off? Thanks alot!
    Last edited by bluntz; 05-17-2009 at 04:09 PM.

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

    Re: merge two worksheets

    bluntz,

    Please post your workbook (or a sample copy) - scroll down and see "Manage Attachments".
    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.

  3. #3
    Registered User
    Join Date
    05-06-2009
    Location
    Florida, USA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: merge two worksheets

    I've attached a sample workbook...the data is arbitrary, just so you get the concept...i have two sheets, one with about 22,000 donors, each with name, address, phone, donor ID. on the second sheet i have about 24,000 donations which were made, each with donor ID, amount, date.

    the donations list has alot of duplicate donor ID's, since people make donations multiple times. the donors list has no duplicate ID's, since each row is a unique person.

    for example i need to look at John Doe's donor ID on row 5, column B of the donors sheet, and then loop through all the donations made on the donations sheet. if i find a donation where the donor ID is the same as John Doe's donor ID, it should add the amount and date to row 5, column B of the donors sheet.
    Attached Files Attached Files

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: merge two worksheets

    You want the donations accumulated count to replace the ID number in column B? Did you mean to say that? Or do you want a new column E with the donations accumulated in it?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: merge two worksheets

    Here's a simple macro for your task. It includes an error check on the IDs, if a donation does not match the Donors list anywhere it will highlight that ID in the Donations list for your later review.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-06-2009
    Location
    Florida, USA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Thumbs up Re: merge two worksheets

    Ok JBeau once again you've helped me fix my macro issue Using my previous code and incorporating some of yours, I came up with this:

    Please Login or Register  to view this content.

    It works extremely efficiently but I'm sure I could optimize the appending part in the middle, I just don't know how. As I type this though, I'm thinking it would have been easier just to make it look for the last cell in the row with data in it. How do you do that? Or if anyone knows a better way, I'd love to see it. Thanks again for the help! SOLVED!

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: merge two worksheets

    If that takes care of your need, be sure to EDIT your original post (Go Advanced) and mark the PREFIX box [SOLVED].

+ 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