+ Reply to Thread
Results 1 to 9 of 9

Would like a Macro to Combine data from the same worksheet in multiple files into one

  1. #1
    Registered User
    Join Date
    11-11-2024
    Location
    Atlanta, GA
    MS-Off Ver
    Microsoft 365
    Posts
    1

    Would like a Macro to Combine data from the same worksheet in multiple files into one

    I have 10 different files in 1 folder. Each file has multiple worksheets and each worksheet is named. All the files have a worksheet named "Out". All the columns in this worksheet named "Out" are the same with different data in each column. I would like to see the VBA code for a macro that would take the data from the same worksheet in all the files and combine the data into one file.

    Thanks,

    Mike

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: Would like a Macro to Combine data from the same worksheet in multiple files into one

    Hi Mike...

    Welcome to the Forum...
    If it is as simple as per your explanation then this will work...
    Place code in a blank workbook and change red snippet to Path of the Folder...
    Untested as I have no sample of these 10 files...
    Please Login or Register  to view this content.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,446

    Re: Would like a Macro to Combine data from the same worksheet in multiple files into one

    Sintek:

    The macro functions as desired but at the end there is a warning message that the main workbook is already open and do you want to reopen it ?

    How to make that go away ?

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: Would like a Macro to Combine data from the same worksheet in multiple files into one

    @Logit...

    Please explain your testing process...
    Last edited by Sintek; 11-12-2024 at 11:17 AM.

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,446

    Re: Would like a Macro to Combine data from the same worksheet in multiple files into one

    I simply ran the macro. No other testing.

    Have to step away for a few hours.

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: Would like a Macro to Combine data from the same worksheet in multiple files into one

    Code goes in blank book...loops the 10 different files in 1 folder extracting, then closing, and combines data in blank book...No errors, runs perfectly for me...

  7. #7
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,446

    Re: Would like a Macro to Combine data from the same worksheet in multiple files into one

    I'm thinking there is a setting in Excel that I am overlooking. But I don't know what or where.

    Here is another macro that does the same thing of copy/paste and then reopens the workbook as read only. I can't figure that out either.
    There are a number of code lines that are commented out during my testing for different solutions.

    Please Login or Register  to view this content.

  8. #8
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,446

    Re: Would like a Macro to Combine data from the same worksheet in multiple files into one

    Sintek :

    After much more research I located the issue with my macro.

    Change this line of code : Set sourceWb = Workbooks.Open(folderPath & fileName, ReadOnly:=True)

    To this : Set sourceWb = Workbooks.Open(folderPath & fileName, ReadOnly:=False)

    Problem solved.



    With your macro I was able to solve my issue with these changes :

    Please Login or Register  to view this content.

    Thank you for your time.

  9. #9
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: Would like a Macro to Combine data from the same worksheet in multiple files into one

    there is a warning message that the main workbook is already open and do you want to reopen it ?
    Cannot understand this as the code does not effect the main book in any way...
    Thank you for your time.
    Where is Mike in all of this...
    Last edited by Sintek; 11-13-2024 at 01:09 AM.

+ 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: 8
    Last Post: 03-14-2017, 03:49 PM
  2. [SOLVED] New to Excel programming. In need of a macro to combine multiple files with multiple tabs.
    By nflores0303 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-12-2016, 11:03 AM
  3. Macro to combine and clean multiple files
    By micahjb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2013, 07:16 PM
  4. [SOLVED] Combine multiple (100+) excel files w/ one worksheet each into one giant worksheet
    By justin11 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 08-03-2013, 01:05 PM
  5. Macro to combine many excel files into one workbook/worksheet
    By excel1983 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-19-2012, 02:32 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