+ Reply to Thread
Results 1 to 13 of 13

VB Code to bring data from lots of files in same folder

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to bring data from lots of files in same folder

    Hello:

    I have lots of excel files in Folder C:\Test\
    Each of the file has the same data strcuture/format, data starts from Row3 down.
    All files have data in Sheet1 with Data range A3:F down.

    I need VB Code to go thru each of these files and consolidate data in single master sheet.

    Please let me know if you have any questions.
    Thanks.

    R

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: VB Code to bring data from lots of files in same folder

    Riz,
    Have you looked at using Power Query. This is just the type of issues that Power Query can handle effectively. Here is a link to how to do this. Power Query is a free add in for Excel 2010
    https://www.youtube.com/watch?v=a7E29H5ZUmE
    https://trumpexcel.com/combine-data-...ple-workbooks/
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to bring data from lots of files in same folder

    Hello alansidman:

    Yes, Power Query can be very good tool.
    In my situation, i need to pass this data and hence need VB for the purpose.

    Please let me know if you have any questions.
    Thanks.

    Riz

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Code to bring data from lots of files in same folder

    Hello Riz,

    Posting a workbook with a sample sheet would help us get started. Thanks.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to bring data from lots of files in same folder

    Hello Leith:

    Attached are sample 3 files which are located at say C:\Temp\ folder

    I need vb code to bring data from all 3 files (Sheet1).

    Please let me know if you have any questions.
    Thanks.

    Riz
    Attached Files Attached Files

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Code to bring data from lots of files in same folder

    Hello Riz,

    Much appreciated!

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: VB Code to bring data from lots of files in same folder

    I know you said that you didn't want to use PQ, but I thought I would show you what it looks like based upon your sample files. If you add additional files to the folder, PQ will automatically append them to the worksheet once you click on the refresh button on the Data tab.
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to bring data from lots of files in same folder

    Hello alan:

    After watching your link, i got tempted to use power query but some data did not import.
    Same thing is happening with your attached file.
    Look at data importd for file # "700033205.xlsx"..Column B and C data are missing.
    Please check and let me know why is it doing this.

    Thanks a lot, for great help.

    Riz

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: VB Code to bring data from lots of files in same folder

    I've never seen anything like that. I will look into this. Columns C and D are blank in the appended file. Yet if I import each file individually, then the data is there. Very strange.
    Last edited by alansidman; 08-02-2019 at 05:41 PM.

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Hi !

    As the files attached have not the same structure : two with 6 columns and one has 7 columns …

  11. #11
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: VB Code to bring data from lots of files in same folder

    Marc

    BINGO!! This one was really driving me nuts and I never noticed the difference.

    Thank you. I can now sleep peacefully tonight.

    Alan

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    LoL ! Have a good night ! Oh, and thanks for the unexpected rep' !

    The reason why I do not propose any code as the expected result workbook is missing again since the initial post …
    Last edited by Marc L; 08-02-2019 at 07:25 PM.

  13. #13
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to bring data from lots of files in same folder

    Hello:

    Oh, thanks a lot for finding out the issue.
    I will work on it now to do Power Query.
    Will let you know if any questions.

    Thanks a ot

    Riz

+ 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] Excel VBA code for selecting a folder then search & open specified files in that folder
    By Excelrookie_1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-27-2021, 03:09 AM
  2. Replies: 2
    Last Post: 10-14-2017, 11:40 AM
  3. [SOLVED] Transfer data from all the files in a folder to all the files in another folder
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-17-2015, 02:06 PM
  4. [SOLVED] VBA Code to Move Individual Files from 1 Folder to a new Folder
    By mike.lawrie448 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 11-21-2014, 07:05 AM
  5. copying data from excel files in a source folder to target folder
    By Javed07 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2013, 04:27 PM
  6. [SOLVED] VBA Code open files in folder, copy text to workbook-Next time folder opened copy only new
    By Bikeman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-02-2013, 07:59 PM
  7. Need Help Fixing Code to Copy Data From Files in a Folder
    By latausm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-08-2011, 12:06 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