+ Reply to Thread
Results 1 to 12 of 12

Copy multiple rows from one book to another based on info in cell D

  1. #1
    Registered User
    Join Date
    11-04-2008
    Location
    Home
    Posts
    22

    Copy multiple rows from one book to another based on info in cell D

    Hi all,

    I am trying to do the following:

    I have a workbook with a single worksheet that has about 2000 rows, columns A, B, C, D, E & F
    Cells in colums A, B, C, E & F all have very different information in them, nothing is similar in any of those columns that I can base a criteria on.
    Cells in column D however will have 1 of about 18 possibilities in them

    What I want to do is have another workbook with 18 worksheets, each worksheet named 1 of the 18 possibilities, and somehow magically pull the data from the first workbook and insert it into the correct worksheet in the second workbook, leaving the data in the first workbook intact.

    I update the first workbook several times a day, adding and deleting from it so would need to update as it goes, or be able to run the update as and when needed.

    My skills are limited to simple formulas inserted into cells and dragging them down!

    I'd really appreciate any help with this.
    Thanks
    Last edited by murphy; 08-24-2009 at 11:51 AM.

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

    Re: Copy multiple rows from one book to another based on info in cell D

    Without seeing the two workbooks directly, not sure I could imagine a formula approach. But a macro could be run to do this pretty well.

    If you provide the names of both workbooks (specify which is which), the full path to where you store these workbooks, I can help with that.

    The macro would:
    1) Open the "output" file if it isn't already open.
    2) Go through all 18 sheets and "filter" the original workbook by the "name" of each worksheet in the second book, copying into the 2nd wb all the rows matching the sheetname.
    3) Save the Output wb and/or close it again. (Your call there)

    Let me know.
    _________________
    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!)

  3. #3
    Registered User
    Join Date
    11-04-2008
    Location
    Home
    Posts
    22

    Re: Copy multiple rows from one book to another based on info in cell D

    I have attached 2 example workbooks, turns out there are 35 possibilities that could be in cells in column D.

    Extracting from Book1 to Book2, data remaining untouched in Book1

    Thanks for your help.
    Last edited by murphy; 08-26-2009 at 10:50 AM.

  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: Copy multiple rows from one book to another based on info in cell D

    Put this macro into Book2 and save it. Book1 and Book2 should reside in the same directory.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-04-2008
    Location
    Home
    Posts
    22

    Re: Copy multiple rows from one book to another based on info in cell D

    Hi JBeaucaire,

    Thanks for that, works very well.

    One thing happening is that when the macro is run from Book2, for some reason it is adding 3 blank worksheets to itself (Book2)

    I'm not sure what is causing this.

  6. #6
    Registered User
    Join Date
    11-04-2008
    Location
    Home
    Posts
    22

    Re: Copy multiple rows from one book to another based on info in cell D

    Neverrmind, I figured it out, one of the worksheets was incorrectly named.

    Thanks again JBeaucaire, I really appreciate it!

  7. #7
    Registered User
    Join Date
    11-04-2008
    Location
    Home
    Posts
    22

    Re: Copy multiple rows from one book to another based on info in cell D

    Oh dear, I have been running the macro on copy and pasted data from my original worksheet and realise that there is more than one worksheet in Book1

    What would I have to add to your code to make the macro target that particular worksheet, excluding the other worksheets?

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

    Re: Copy multiple rows from one book to another based on info in cell D

    Which worksheet? You would add this line in red and edit it to your need:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-04-2008
    Location
    Home
    Posts
    22

    Re: Copy multiple rows from one book to another based on info in cell D

    Hi JBeaucaire,

    Thats great, works like a charm now.
    Though if I have both books open, run the macro from Book2, once it's finished Book1 closes for some reason.

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

    Re: Copy multiple rows from one book to another based on info in cell D

    It's designed that way. This code assumes it is was closed and we opened it and should now close it again.
    Please Login or Register  to view this content.
    We can check to see if it was open, and leave it open if it was:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-04-2008
    Location
    Home
    Posts
    22

    Re: Copy multiple rows from one book to another based on info in cell D

    Hi JBeaucaire,

    Thanks for all your help, just what I was after.

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

    Re: Copy multiple rows from one book to another based on info in cell D

    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED]. If the prefix box is no longer available, just add SOLVED to the start of the title.

    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)

+ 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