+ Reply to Thread
Results 1 to 19 of 19

Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is same

  1. #1
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is same

    Hi everyone,

    I have 3 workbooks with multiple worksheets. Workbook1, Workbook2, Workbook3

    All three workbooks can be open at the same time

    I have a list of worksheet names found in Master_Workbook column A1

    What I'm trying to do is have a macro which will loop through the list of worksheet names in Master_Workbook column A1, and look through all three workbooks. If at least two workbooks have a worksheet with the same name, it will merge to the two (or three) into a new workbook with the same name.

    I've been doing some research on this but I haven't been able to find anything quite like this.

    Any ideas?

    Thanks!!

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    With the Master Workbook and the 3 other workbooks as the only open workbooks that are visible at the time that the macro is run, and with the code in the master workbook and the worksheet named "Master", run this code. The new workbooks will be created in the same folder as where the workbook with the macro is stored.

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    Hi Bernie,

    Thank you very much for your code, as well as your post on the developers forum where I also inquired for help! I'm trying to make some small adjustments to your code to fit the actual workbook. I have updated the master sheet name. The list of worksheet names is now found in cell P3 and down rather than A1. I ran your code with the adjustments I was able to make, and there were no errors, however I found that the new workbooks only contained one worksheet rather than up to 3 and that column A:A seemed to list the workbook name the data came from. Is the data being copied into a single sheet? If so, how can we adjust so that each sheet appears separately in the new workbook? I apologies if my description was the cause of this confusion.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    Yes, my code creates a single sheet from all the sheets of that name - that was my interpretation of what you posted. So try this - I took out all code that lists the parent workbook name - not sure if you need that or not.

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 04-06-2017 at 03:42 PM.

  5. #5
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    Hi Bernie,

    Thank you for removing the references. I'm trying to understand your code for my own knowledge as this type of coding is quite a bit beyond my current skill level. Do I understand correctly that the following section of code copies the worksheets into the new workbook as new worksheets rather than copying the data from the 3 worksheets into a single worksheet in the new workbook?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    That's what it should do - did you try the code? I did not test it this time since it was a small change....

  7. #7
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    Hi Bernie,

    The code works perfectly, thank you! One last thing. Master_Workbook has a sheet called Sum. I need to copy the Sum sheet to each of the output workbooks, so it would be the 3 worksheets plus a copy of the Sum sheet in front of them. I'm trying to add it into your code without much success. Can you assist?

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    After this line
    Please Login or Register  to view this content.
    Add this line

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    Hi Bernie,

    You've been awesome so far, thanks very much for your help. Two questions:

    1. Worksheets("Sum") in the newly created workbook (with the other 3 worksheets we added).range("D15") needs to equal worksheet(2) (the 2nd worksheet in the new workbook).Range("D44"). How can I reference this?
    2. Similar to the top, Worksheets("Sum").Range("D16") needs to equal Workbooks("Master_Workbook.xlsx").Worksheets("Supplimentary").Range("B12"). How can I reference this?

    Thanks!!

  10. #10
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    After this line:

    Please Login or Register  to view this content.
    Add these two lines:

    Please Login or Register  to view this content.
    But, isn't Master_Workbook a macro-enabled .xlsm file?

    PS "Supplementary" is the correct spelling of "Supplimentary"

    (Just in case that is a work-related workbook...)

  11. #11
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    Hi Bernie,

    Thanks. I actually used those same codes you entered but I'm not getting the values copied over. range("D44").value has a formula in it. Does that make a difference?

  12. #12
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    It shouldn't - what do you get with:


    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    Ah, I figured it out. Just need to put the .value = .value lines lower in the code. I put them after I delete a couple of unused worksheets.

  14. #14
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    Hi Bernie,

    For
    Please Login or Register  to view this content.
    Instead of specifically identifying cell D44 in Worksheets(2), how can I adjust this to select the last cell in row 44 with data. Not all cells in this row contain data, so its the absolutely last cell in this row that contains it. The data in this row won't go beyond column Z.

    Thanks!!

  15. #15
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    Ah, figured it out. Admittedly a backwards way of doing it:

    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    Hi Bernie,

    Now I definitely need your assistant. For pulling the a value from the Master_Workbook workbook
    Please Login or Register  to view this content.
    What I'd like to do is copy an entire range. So instead of icking B12 specifically, the line would look through column A of worksheets("Supplementary") find the value which is the same as the rngC.value, then copy the values adjacent to it in column B and 5 rows down. So if it happen to find rngC.value in say A23, then it would copy B23-B28 to worksheets("Sum").range("D16") and down.

    Any ideas?

    Thanks!!

    Any ideas?

  17. #17
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    Change Supplimentary to Supplementary if you have corrected your worksheet name:

    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    Hi Bernie,

    The code seems to be copying the data in Supplementary across to the right instead of down 5 rows?

  19. #19
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Combine up to 3 worksheets from up to 3 workbooks into new workbook if Sheet name is s

    D'oh!

    Please Login or Register  to view this content.

+ 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: 4
    Last Post: 07-31-2016, 04:17 PM
  2. [SOLVED] Combine worksheets from multiple workbooks in a new workbook
    By teton88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-27-2014, 01:14 PM
  3. [SOLVED] combine multi workbooks into one master workbook but I want to combine only sheet 3
    By Goodstart14 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-31-2013, 12:22 AM
  4. How to combine specific worksheets from different workbooks into one workbook?
    By thepulser89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2013, 03:44 AM
  5. Replies: 5
    Last Post: 02-25-2013, 08:21 AM
  6. How to combine multiple worksheets in multiple workbooks into one workbook
    By tianshu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-19-2012, 11:01 AM
  7. [SOLVED] Combine multiple workbooks into 1 workbook w/ multiple worksheets
    By buffgirl71 in forum Excel General
    Replies: 2
    Last Post: 05-12-2006, 05:35 PM

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