+ Reply to Thread
Results 1 to 8 of 8

Consolidate Mutiple FIles in Multiple Directories into 1 File

  1. #1
    Registered User
    Join Date
    03-16-2016
    Location
    Philadelphia
    MS-Off Ver
    Office 365
    Posts
    8

    Consolidate Mutiple FIles in Multiple Directories into 1 File

    WE have a directory with various subfolders that houses source files where data is being captured. WE then would like to merge all that data into 1 workbook that can be updated to capture any changes. Ill explain in more detail.

    Our directory is U:\L&S. Subfolders are Set1, Set2, Set3, and Set4. Each of these subfolders has its own file where people will be entering data. So Set 1 folder has a file named 2_Set1.xlsx. Set 2 folder has a file named 2_Set2.xlsx, etc. The columns in each file are exactly the same.

    We want to create a master file that will merge all 4 of these files into 1 and we want the master file to be able to be updated at any time to capture any changes in any of the Set files.

    Any thoughts? I am a beginner in VB.

    Thanks

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Consolidate Mutiple FIles in Multiple Directories into 1 File

    As for thoughts:
    I'd store in master file not only information captured from source files, but also from each file it was captured. It could be either by storing each source file data in a separate worksheet in master workbook, or, if data is to be stored in a common worksheet - then in cell next to data its source. otherwise it will be tough task to screen for changes (even impossible if you move some data from one source to another - so there is a change, but a master file would look the same if no informaton about source file is stored).
    Best Regards,

    Kaper

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Consolidate Mutiple FIles in Multiple Directories into 1 File

    Running from the Master, you may be able to use the FileSystemObject feature periodically to look for the DateLastModified of the Set files to isolate which sections require updating - it may be best, however, to put them on their own tabs in the master. Another thought
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Registered User
    Join Date
    04-13-2016
    Location
    manila, philippines
    MS-Off Ver
    10
    Posts
    6

    Re: Consolidate Mutiple FIles in Multiple Directories into 1 File

    try using this one

    Sub CombineSubfolderFiles()

    'copies rows from first worksheet of all Excel files in first subfolders
    'level of a given folder.

    Dim Fs As Object 'FileSystem
    Dim D As Object 'Folder
    Dim Fx As Object 'Subfolder
    Dim File As Object 'File
    Dim PathName As String
    Dim iRow As Long 'next available row index of destination worksheet
    Dim LRow As Long 'last row of source worksheet

    With Worksheets(1) 'data destination worksheet

    Set Fs = CreateObject("Scripting.FileSystemObject")
    Set D = Fs.GetFolder("C:\Users\badronanl\Desktop\latest proj")
    iRow = 1

    For Each Fx In D.subfolders 'loop through subfolders

    For Each File In Fx.Files 'loop through files
    If File.Name Like "*.xls" Then
    PathName = Fx.Name & "\" & File.Name
    Workbooks.Open D.Path & "\" & PathName
    Application.StatusBar = "Processing " & PathName
    'copy rows to last row having data in column A
    LRow = Worksheets(1).Range("A65536").End(xlUp).Row
    Range(Rows(20), Rows(LRow)).Copy Destination:=.Rows(iRow)
    ActiveWorkbook.Close
    End If
    iRow = iRow + LRow
    Next File

    Next Fx

    End With 'Worksheets(1) of this workbook

    End Sub

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Consolidate Mutiple FIles in Multiple Directories into 1 File

    Hi Stormtrooper,

    You need to put your code in code tags - it looks like pretty good code - here are the directions:

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. here


    And - welcome to the Forum!

  6. #6
    Registered User
    Join Date
    04-13-2016
    Location
    manila, philippines
    MS-Off Ver
    10
    Posts
    6

    Re: Consolidate Mutiple FIles in Multiple Directories into 1 File

    Hello xladept,

    Thanks for the advice! I was actually thinking of doing it but i don't know how.


    Please Login or Register  to view this content.
    just wanna try it! )

    thanks!

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Consolidate Mutiple FIles in Multiple Directories into 1 File

    Hi Stormtrooper,

    Thanks for the rep!

    You can put code tags on your first post - by editing it

    And the OP's path is actually:
    Please Login or Register  to view this content.
    Last edited by xladept; 04-15-2016 at 10:42 AM.

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Consolidate Mutiple FIles in Multiple Directories into 1 File

    @ tstagliano- What do you mean by merge? Do you mean an actual ordered list? And, if so, how are they ordered. Or, if not, is it a stacked list that you want?

+ 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: 6
    Last Post: 11-14-2014, 11:04 AM
  2. Copy Files to Folders Based on Specified File Names and Directories.
    By mamero in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-22-2013, 12:08 PM
  3. Consolidate data from multiple excel files into single file
    By hkkk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2013, 03:34 AM
  4. Consolidate data from multiple excel files into single file
    By hkkk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-22-2013, 12:36 AM
  5. copy files located in multiple directories that match a partial value
    By msheen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-18-2012, 04:55 PM
  6. Consolidate Data from Multiple Files (Different File Names) into a Master File
    By dspraveen_23 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-08-2012, 12:59 PM
  7. Search text in multiple files in multiple directories
    By Andrew in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-31-2006, 10:48 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