+ Reply to Thread
Results 1 to 11 of 11

Combine ranges A1:B100 for all xlsx files in a folder into a new file

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

    Combine ranges A1:B100 for all xlsx files in a folder into a new file

    Hi everyone,

    I have a folder which contains over 100 Excel files (all with extension xlsx). Now I want to extract data for the range A1:B100 for each of these files and put them into columns A:B of a new file. So in the new file, range A1:B100 is for the 1st Excel file, A101:B200 is for the 2nd Excel file, A201:B300 is for the 3rd Excel file, and so on.

    I can do it manually but this will be really take a long time by doing copy and paste.

    I did some search online and there is something called CreateObject("Scripting.FileSystemObject"). But I really don't know how to do with that.

    Thanks in advance for help.

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Combine ranges A1:B100 for all xlsx files in a folder into a new file

    Hi

    In order to copy the contents of files you will have to open them all, I think.

    Try this macro. It will open each workbook in the directory you specify and copy range A1:b100 into your active workbook, then close the source file.

    replace C:\MyFolder\ with your source folder (include the final \ )

    Please Login or Register  to view this content.

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

    Re: Combine ranges A1:B100 for all xlsx files in a folder into a new file

    Many thanks, NickyC.

    Just wondering if there is a way that we don't need to open all these Excel files in the folder. For my case, the computer will crash if I have to open all these 100+ files.

    Thanks everyone.

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

    Re: Combine ranges A1:B100 for all xlsx files in a folder into a new file

    No one can really deal with this question?

  5. #5
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Combine ranges A1:B100 for all xlsx files in a folder into a new file

    Are you just assuming it crashes or does it actually crash? If so at what point does it crash?

    As a quick fix to crashing I put a message in my code to stop it every X files.

    I have a couple of computer setups one that has an issue and one that doesn't with doing large numbers of these files like this not clear exactly why.
    Last edited by scottiex; 02-28-2017 at 09:39 PM.

  6. #6
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Combine ranges A1:B100 for all xlsx files in a folder into a new file

    It is possible to link to unopened cells, but I think it only works one cell at a time.
    try this website for some tips:

    http://spreadsheetpage.com/index.php...a_closed_file/

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: Combine ranges A1:B100 for all xlsx files in a folder into a new file

    Have you tried the code?
    As scottiex mentioned, it sounds like you assume that because the code closes the workbooks after it copied the data.

    Here are two more, similar to the code from NickyC.
    The workbook with the code in it needs to be saved in the same Folder where the other workbooks are saved.

    One does a copy and paste while the other pastes the values only

    Please Login or Register  to view this content.



    Please Login or Register  to view this content.
    If your computer does crash, let us know and it can be done with formulae

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Combine ranges A1:B100 for all xlsx files in a folder into a new file

    If the worksheet names that you are reading from are common then
    one way
    Please Login or Register  to view this content.

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

    Re: Combine ranges A1:B100 for all xlsx files in a folder into a new file

    Hi Jindon, your code is really like a magic. It is neat and so powerful. Certainly it is very useful to me (save me a lot of trouble by doing copy/paste manually).

    At the same time, many thanks to NickyC and jolivanes. Your code are useful for me to learn and apply.

    I hope the macros here can be useful to others too. Really thanks to the many help from the VBA gurus in this forum

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

    Re: Combine ranges A1:B100 for all xlsx files in a folder into a new file

    And the macro by Jindon doesn't require the source data files to be opened/ closed. It is very fast to run. Amazing!

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Combine ranges A1:B100 for all xlsx files in a folder into a new file

    You are welcome and thanks for the feedback.

+ 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: 1
    Last Post: 12-01-2016, 10:57 AM
  2. Replies: 4
    Last Post: 10-04-2015, 08:21 AM
  3. [SOLVED] Looping through all files in a folder - save as xlsx
    By Emse_ in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-18-2014, 02:15 PM
  4. Replies: 3
    Last Post: 01-05-2014, 05:50 AM
  5. How to add the columns data of several xlsx files of a folder in another xlsx file
    By ravikumar00008 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-25-2012, 04:29 AM
  6. Macro to open & close mutiple xlsx files in folder
    By bernard.x in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-20-2012, 06:18 AM
  7. Replies: 4
    Last Post: 09-22-2010, 01:22 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