+ Reply to Thread
Results 1 to 10 of 10

How to adapt the macro to allow it to consolidate files with multiple sheets?

  1. #1
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019
    Posts
    436

    How to adapt the macro to allow it to consolidate files with multiple sheets?

    The macro below is able to combine multiple Excel files in a folder into a single workbook (each sheet of the new workbook represents the original individual Excel file). The little drawback is that the original Excel files is ONLY allowed to have ONE sheet for this macro to work. If a file has multiple sheets, then only one sheet is used for the consolidation.

    Is there a way to modify it to allow it to accommodate multiple sheets of files to be consolidated?


    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,364

    Re: How to adapt the macro to allow it to consolidate files with multiple sheets?

    Can't test it now but you'd define a variable "Dim sh As Worksheet" and then say:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019
    Posts
    436

    Re: How to adapt the macro to allow it to consolidate files with multiple sheets?

    I adapted the macro as below, but still has a error which said:

    Run-time error '1004': Application-defined or object-defined error

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019
    Posts
    436

    Re: How to adapt the macro to allow it to consolidate files with multiple sheets?

    Can you please help to take a look at the macro code? It said 'Run-time error '1004': Application-defined or object-defined error'

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: How to adapt the macro to allow it to consolidate files with multiple sheets?

    In which line of the code do you get the error, so that it would be easy to identify it?

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: How to adapt the macro to allow it to consolidate files with multiple sheets?

    Hi, billj,

    wouldn´t it be simpler to copy the worksheets instead of adding a blank one in the master and then copy the contents across?

    Maybe you should rethink the way to name a sheet to a file name if multiple sheets from that workbook are copied.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  7. #7
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019
    Posts
    436

    Re: How to adapt the macro to allow it to consolidate files with multiple sheets?

    Thanks for the advice. I attached the file with the macro included.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019
    Posts
    436

    Re: How to adapt the macro to allow it to consolidate files with multiple sheets?

    Still waiting for an answer. Can anyone please help for the macro?

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: How to adapt the macro to allow it to consolidate files with multiple sheets?

    Hi, billj,

    Still waiting for an answer.
    Well, if you want to copy multiple sheets from one workbook and assign the very same name to a worksheet that is already in the current workbook Excel VBA will raise a run-time Error. So you would need a different method than the one you used when only copying one sheet.

    Please Login or Register  to view this content.
    is good enough if there is one sheet which is given the name, for multiple sheets you should alter it to something like
    Please Login or Register  to view this content.
    Ciao,
    Holger

  10. #10
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019
    Posts
    436

    Re: How to adapt the macro to allow it to consolidate files with multiple sheets?

    Hello HaHoBe, thanks a lot for the help. Your improved formula worked perfectly

+ 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] Need help with a macro to consolidate data from multiple sheets into one
    By xdskyline in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-15-2013, 06:21 PM
  2. [SOLVED] Macro to read the multiple csv files and consolidate into single excel
    By parthmittal2007 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 01-03-2013, 03:40 AM
  3. [SOLVED] Need macro to consolidate data from select multiple sheets
    By titusingh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-16-2012, 08:29 AM
  4. Help! Macro to consolidate data from multiple workbook sheets!
    By Sainath Krishnan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2012, 08:18 AM
  5. Macro to oepn multiple txt files and then consolidate
    By Nonboff in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-26-2009, 09:44 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