+ Reply to Thread
Results 1 to 9 of 9

Merge many sheets into one, re-order cols, include sheet name on merged sheet rows

  1. #1
    Registered User
    Join Date
    04-08-2014
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    29

    Merge many sheets into one, re-order cols, include sheet name on merged sheet rows

    Hi, im a new memeber but long time troll. Learned lots here, appreciate everyones help here!

    I have a huge project, 5 yrs of workbooks needs merged onto 1 worksheet.
    Each workbook contains indiv state-named worksheets.
    Want to merge all the sheets on 1 master per workbook, i'll worry about merging the workbooks later...

    Found some cool code to merge the sheets but needs tweaked some.
    I write ASP.NET (vb) and very handy with excel 2007 complex formulas etc but vba is not my strong suit...

    tweaks to this merge code i need are:

    1 - exclude hidden worksheets when merging
    2 - exclude blank rows when merging
    3 - can the columns be re-ordered (heading names match on the indiv sheets, but may not be in same order)
    4 - add the source sheet name to each row Col A on the merged sheet.

    I'm uploading a sample with the merge code included module, any help would be SOO appreciated!
    Attached Files Attached Files

  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: Merge many sheets into one, re-order cols, include sheet name on merged sheet rows

    Some base macros you can use as a starting point in your project:




    Here's a macro for merging data from multiple sheets into a "consolidation" sheet where the source sheets' columns are not in the same order, but DO have the same header titles. Setup your consolidation sheet headers for columns in the order you want, then the macro matches those headers to wherever the header is found in each sheet and copies the correct data from each column to correct position in the consolidation sheet.
    'WORKBOOKS TO SHEETS
    Here's a macro for collecting data from all files in a specific folder. This version copies the sheet in as a whole.The parts of the code that need to be edited are colored to draw your attention.


    Perhaps both will assist in certain parts of your process?
    Last edited by JBeaucaire; 12-27-2019 at 03:54 AM.
    _________________
    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
    04-08-2014
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    29

    Re: Merge many sheets into one, re-order cols, include sheet name on merged sheet rows

    Thanks so much, i will give this a try and see how it works out!

  4. #4
    Registered User
    Join Date
    04-08-2014
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    29

    Re: Merge many sheets into one, re-order cols, include sheet name on merged sheet rows

    Thanks so much for submitting your sample codes (nice webpage you have, i will have to explore when i have time)

    i made a little time to test your combining worksheets code today. the column re-ordering is GREAT. nice function there, i will definately find use for that! and the sheet names are included in col A as i hoped for, fantastic...

    is there a way to NOT pull hidden worksheets, to only combine the visible ones?

    the code sample i originally included in my sample file attachment finds the last used row on each worksheet and lets user set which row is the header row, but i don't see that in your code (not yet anyway have not had alot of time to go thru it yet). i can try to add those features into yours, not sure how successful i will be..

  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 many sheets into one, re-order cols, include sheet name on merged sheet rows

    To test is a given worksheet is visible or not:

    Please Login or Register  to view this content.
    The part in green is finding the lastrow of data on each sheet.

  6. #6
    Registered User
    Join Date
    04-08-2014
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    29

    Re: Merge many sheets into one, re-order cols, include sheet name on merged sheet rows

    Please Login or Register  to view this content.
    I wonder if this LastRow code is finding like last cell on a worksheet (which maybe due to formats etc), as opposed to last USED row with data populated in the cells on the row, you understand what i mean?

  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 many sheets into one, re-order cols, include sheet name on merged sheet rows

    If you know you want the last row with data using a specific column, like column A, I also use this technique:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-08-2014
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    29

    Re: Merge many sheets into one, re-order cols, include sheet name on merged sheet rows

    Yes that will help alot, thanks!

  9. #9
    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 many sheets into one, re-order cols, include sheet name on merged sheet rows

    I've marked this thread as SOLVED for you.
    Next time, select Thread Tools from the links above to mark a thread as SOLVED. Thanks.

+ 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. [SOLVED] Merged mulitple sheets of existing workbook into one sheet
    By paradise2sr in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-01-2014, 04:04 AM
  2. Macro which will copy rows of data, in same order from one sheet, to another sheet!
    By WaylettChris in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-23-2013, 02:02 PM
  3. [SOLVED] Compilation of Multiple Cols into 2 Cols in new sheet
    By hammer2 in forum Excel General
    Replies: 4
    Last Post: 07-31-2012, 06:46 AM
  4. copying cols from another sheet to the active sheet
    By jartzh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-01-2011, 06:01 PM
  5. Copy rows and cols from one sheet to another.
    By jmadsen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2010, 04:13 PM

Tags for this Thread

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