+ Reply to Thread
Results 1 to 18 of 18

Excel VBA to import all the data of various files into 1 file in the same folder

  1. #1
    Registered User
    Join Date
    09-17-2008
    Location
    Europe
    Posts
    48

    Excel VBA to import all the data of various files into 1 file in the same folder

    Hi,

    I have a list of excel (2010 version) files in a folder (eg: c:\temp\work\). The files in this list are all in the same format and contain 1 sheet in each file.

    I need a VBA to import the data in each file, found in the folder above, into one worksheet, listing the contents of each file, and then save the new file with the combined data. However, the code needs to be dynamic in the same that the number of files and the filenames change, therefore, the code has to automatically pick up the list of files in the folder.



    Can anyone help, please.


    regards,
    makku

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    There are a few ways of importing data, but it would help if you could upload a sample workbook of the data you are wanting to extract from as well as a workbook with the desired outcome.

    There's a thread here with a couple of approaches. http://www.excelforum.com/excel-prog...atabase-2.html

  3. #3
    Registered User
    Join Date
    09-17-2008
    Location
    Europe
    Posts
    48

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    Basically what i need is a code that opens all the files in a folder, copies all the content (of each file), and pastes into another file which will eventually contain all the info. pasted from the individual files.


    regards,

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    If you can upload a sample workbook as requested, we can have a look, without this, all I can do is point you at the thread above which poses the same question

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    May I also suggest you upload a sample file that would be normally imported. The structure of both files is important for us to view.

    Hope this helps.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  6. #6
    Registered User
    Join Date
    09-17-2008
    Location
    Europe
    Posts
    48

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    Hi,

    As suggested attached please find 2 sample files. As already mentioned these files will be found in a specific folder (amongst other files). I would like the contents in all the files in this folder to be imported and saved into 1 file in 1 sheet.


    regards,
    2011-12-PRODA.xlsx2011-11-MEDIAA.xlsx
    Last edited by makku; 12-06-2011 at 08:35 AM.

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    I think something went wrong when you tried to upload your files, I can't open either of them, could you try and add them again please?

  8. #8
    Registered User
    Join Date
    09-17-2008
    Location
    Europe
    Posts
    48

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    I tried to upload again and i still get the error. However, you can view the files by clicking on the paper clip in the main thread of "excel-programming (http://www.excelforum.com/excel-programming/) next to my post.

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    Ok Got em , I'll have a look

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    give this a whirl, you just need to change the path at the top to where you have all your workbooks saved that you are importing. This code goes in the workbook that summarises the data.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    09-17-2008
    Location
    Europe
    Posts
    48

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    Thanks. It worked great!

    One last question. How can i import the data into an existing file with a particular sheetname "Actual Costs" into cell D4?


    regards,

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    So the same as before but with a different sheet name and the top left cell as D4?

  13. #13
    Registered User
    Join Date
    09-17-2008
    Location
    Europe
    Posts
    48

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    Yes, the same but i would like to get the result in a sheetname called "Actual Costs" and the info. will be pasted starting cell D4 in this sheet.

  14. #14
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    Depending on what's in the surrounding cells of D4

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    09-17-2008
    Location
    Europe
    Posts
    48

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    I'm getting a "Run-time error '13': type mismatch on the line:

    Please Login or Register  to view this content.

    regards,

  16. #16
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    Could you post a copy of your workbook?

  17. #17
    Registered User
    Join Date
    09-17-2008
    Location
    Europe
    Posts
    48

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    See attached file.

    It seems to be working, however, the result is being inserted in the sheet called "Blank1" not in the "Actual Costs" sheet. Please note that this is just an extract of the combined.xlsm file... there are more sheets that i have removed!


    regards,
    Attached Files Attached Files

  18. #18
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Excel VBA to import all the data of various files into 1 file in the same folder

    I can't replicate your error, is the actual costs sheet exactly the same as in your real workbook, also I can't see how my revised code can put the data into "Blank1" sheet. Using your workbook, the code works fine for me.

    The only change is the starting point for dumping the data. Please try running this in the sample that you uploaded. If it works in that, then the problem lies in your actual workbook

    Please Login or Register  to view this content.

+ 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