+ Reply to Thread
Results 1 to 26 of 26

Macro to merge multiple sheets into one

  1. #1
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Macro to merge multiple sheets into one

    Hello Folks

    I am in need of a macro to consolidate multiple sheets into one sheet with following conditions,

    1) The header labels need to be copied over to the new sheet.
    2) All data from individual sheets except the last row (Total Row) needs to be copied over to the newsheet.
    3) The last column after transfer of data needs to be populated with the Respective Sheet names.

    Attached is an example with requirement described.

    Appreciate any help.

    Thanks
    Kris
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Macro to merge multiple sheets into one

    Hi Kris,

    Let us know how this goes:

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro to merge multiple sheets into one

    Hi Robert,


    Thanks for your reply. The Code debugs @ 3rd line after Each Statement ie
    LngPasteRow =- Sheets("Merged Data"). This is because the code assumes that there would be an existing sheet named Merged Data
    to which it is trying to copy. In the example I provided, I had manually done the consolidation to showcase of what I wanted. I want the macro to create a new sheet with all the consolidated data being copied over. Also, the column range A&D in my attached example is only for illustration purpose,
    but in my real task , the no of columns may vary , however it would be the same across all the sheets.

    Can you please suggest a revised code with the above points being taken care.

    Thanks
    Kris

  4. #4
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Macro to merge multiple sheets into one

    Hi,

    Attached is my solution. Hope this helps.
    Attached Files Attached Files
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  5. #5
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro to merge multiple sheets into one

    Perfect mate! Thanks heaps guys.

  6. #6
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Macro to merge multiple sheets into one

    You are welcome.

  7. #7
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Macro to merge multiple sheets into one

    Ah, I see xlbiznes has beaten me to the punch!! In case someone can't download from the site, here's my attempt nonetheless:

    Please Login or Register  to view this content.
    HTH

    Robert

  8. #8
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Macro to merge multiple sheets into one

    Assuming "Merged Data" sheet doesn't exist, try this code.........
    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  9. #9
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro to merge multiple sheets into one

    Hi xlbiznes

    I just need to change a little bit different approach to what I initially requested.
    Basically, I would keep the merged data sheet always and will copy over the source sheets every month.
    Is it possible to include a macro code, to first erase the contents of columns A to Z of Merged Sheets first and then
    combine the source sheets.

    On a separate note, I just need a code to paste special a column to divide by a constant number say 3. To illustrate say Column C
    has Average of 3 months data and I just need to convert it into a monthly average and so I need a macro to copy and paste special C
    with Values in Columns C divided by 3.

    Thanks for your help.

  10. #10
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Macro to merge multiple sheets into one

    Hi,

    for the first request, can you add this line of code as shown below:

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro to merge multiple sheets into one

    Awesome Xlbiznes. Thank you very much.

  12. #12
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Macro to merge multiple sheets into one

    You are welcome. Will provide the other request later . Its past bed time here.

  13. #13
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro to merge multiple sheets into one

    No worries. Good Night

  14. #14
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro to merge multiple sheets into one

    Hi Xlbiznes

    I just experienced that I have added one more sheet and have hidden that worksheet , however the macro
    is merging the data from the hidden sheet as well.This hidden sheet is required as some of the data is flowing into the Merged Data sheet.
    Can you make your code to merge only visible sheets into the "Merged Data Sheet".

    Sorry for being inconvenient.

    Regards
    Kris

  15. #15
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Macro to merge multiple sheets into one

    Do we need to give an input box for the month average at the beginning of the process so that we can compute the monthly average next to the total value.

  16. #16
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Macro to merge multiple sheets into one

    Anyways , here is the updated one to take care of hidden sheets.
    Attached Files Attached Files

  17. #17
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro to merge multiple sheets into one

    Hi Xlbiznes,

    I have found the solution for the converting the average. please discard this request.
    However would you be able to help me on the Original request for Merging Data. Only the visible sheets should be copied into the Merged data.
    Appreciate if you can suggest a code which I can add to your original solution.

    Thanks

  18. #18
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Macro to merge multiple sheets into one

    I had already uploaded the updated file. Did u check that.

  19. #19
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro to merge multiple sheets into one

    I have got the solution for monthly average. Please discard this request.
    Appreciate if you can tweak your original solutions for merging sheets but need only for visible sheets only.

    Thanks

  20. #20
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro to merge multiple sheets into one

    Sorry checking it now

  21. #21
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro to merge multiple sheets into one

    Thanks a lot my friend.

  22. #22
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro to merge multiple sheets into one

    Hi Trebor

    Can you help me to add a line to ignore two sheets which holds pivot table before
    merging visible sheets into the "Merged Data" sheet.
    Below is my current code which works fine.
    HTML Code: 

  23. #23
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Macro to merge multiple sheets into one

    Hi Kris,

    Say the additional tab is called 'MyPivot' (change to suit), see if changing this line of code...

    Please Login or Register  to view this content.
    ...to this does the job:

    Please Login or Register  to view this content.
    Regards,

    Robert
    Last edited by Trebor76; 12-18-2013 at 07:24 PM.

  24. #24
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro to merge multiple sheets into one

    Hi Robert

    Though the code ignores the pivot table sheet but after the code is run,
    the pivot table disappears from the sheet. I have got a dynamic named range for the pivot.
    Not sure why pivot table gets deleted.

  25. #25
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Macro to merge multiple sheets into one

    As I'm not the author of the code you've posted it's hard for me to give an answer.

    You may to have reset the relevant named range after the code is run, especially if it's based on the Merged Data tab as the range in this tab is obviously changed each time the RunProcess macro is executed.

    Robert

  26. #26
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Macro to merge multiple sheets into one

    The code that trebor76 has posted :

    Please Login or Register  to view this content.
    should work fine, because there is no code that is executed other than the for loop if the condition is true.


    @Mysore,

    Whats is the data source for the Pivot Table ?

+ 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. Merge multiple sheets into one Sheet
    By vijaybharthi in forum Excel General
    Replies: 15
    Last Post: 11-07-2012, 08:19 AM
  2. Merge multiple excel files into one with multiple sheets
    By madmanmarz in forum Excel General
    Replies: 3
    Last Post: 05-23-2012, 10:10 AM
  3. Merge multiple excels with multiple sheets in a master excel with multiple sheets
    By marchi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-15-2012, 10:37 AM
  4. VBA to merge multiple Workbooks with multiple sheets retaining headers
    By LauraN1 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 08-19-2010, 03:47 PM
  5. Replies: 3
    Last Post: 03-03-2010, 03:41 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