+ Reply to Thread
Results 1 to 12 of 12

Multiple Files in a folder - Copying to one file

  1. #1
    Registered User
    Join Date
    12-21-2012
    Location
    St Paul ,USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Multiple Files in a folder - Copying to one file

    Hi

    I am new to VB

    I have a folder containing mutiple files for the month of December, each are dated for each day eg 12.01.12

    Is there a way of opening each file and copying the information (from Sheet1) into one master file within the folder

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Multiple Files in a folder - Copying to one file

    Welcome to the Forum!

    Yes, that's possible. To provide further details, can you describe how the data is to be copied into the master file? That is, do you want each Sheet1 from each individual file to be copied to a separate worksheet in the master? Or are they all stacked up somehow in the worksheet in the Master?

    I'm assuming this is strictly a copy & paste, and you don't need to do any of analysis or aggregation of the data.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    12-21-2012
    Location
    St Paul ,USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Multiple Files in a folder - Copying to one file

    Hi

    Glad to join, thanks for helping

    I have a master folder containing files all dated for example december .(I would like code I could reuse in each months folder, if that is possible)

    Each Sheet1 from each individual file , in this case 20 files , to be copied to a new separate worksheet (called master) that would list all the information from the 20 files on one sheet within the folder

    It is strictly copying the data from the multiple files (all the same format) and pasting to one file

    Does that help?
    Last edited by ingwingfingerling; 12-21-2012 at 11:01 AM.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Multiple Files in a folder - Copying to one file

    Attached is a solution where the contents of each worksheet is pasted below the contents of the previous. Push the button and a separate master file will be created. After all content has been added, the master file is left open and you will to manually save it.

    File removed, see correction below
    Last edited by 6StringJazzer; 12-21-2012 at 05:45 PM. Reason: File removed, see correction below

  5. #5
    Registered User
    Join Date
    12-21-2012
    Location
    St Paul ,USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Multiple Files in a folder - Copying to one file

    Thanks

    I get an error

    Compile error : Variable not defined

    Any ideas what I might be doing wrong?

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Multiple Files in a folder - Copying to one file

    I'm very sorry, I dropped a colon. I made one small change just after I tested it, and that change had an error in it

    See attached.

  7. #7
    Registered User
    Join Date
    12-21-2012
    Location
    St Paul ,USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Multiple Files in a folder - Copying to one file

    It works with one small error

    It copies on the master across the columns

    If it could copy the files (without the header) below the columns

    Sorry for not being clear

    Thanks for your help so far!

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Multiple Files in a folder - Copying to one file

    It is so important to provide a complete description from the beginning.

    This solution copies the first file, and pastes it starting at A1 of the master.
    It copies the second file, then pastes it starting in column A, in the row after the end of the data from the first file.
    And so on.

    How is that copying "on the master across the columns"? It is pasting downwards. What does it mean to copy "(without the header) below the columns"? A column is cells of data; there is no such thing as below a column.

    I suggest you build a master by hand by copying and pasting just two files, and then attach all three files so I can see exactly what you want the result to look like.

  9. #9
    Registered User
    Join Date
    12-21-2012
    Location
    St Paul ,USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Multiple Files in a folder - Copying to one file


  10. #10
    Registered User
    Join Date
    12-21-2012
    Location
    St Paul ,USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Multiple Files in a folder - Copying to one file

    Quote Originally Posted by ingwingfingerling View Post
    Hope this makes it a bit clearer . Thanks for all your help and patience

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Multiple Files in a folder - Copying to one file

    Based on your samples, the only thing you need to change is to exclude the header from the source files when making the master. This version asks you whether you want to include them.

  12. #12
    Registered User
    Join Date
    12-21-2012
    Location
    St Paul ,USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Multiple Files in a folder - Copying to one file

    Hi that works great

    Thanks for your help and sharing!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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