Appending Files in subfolders with inconsistent names

Walser52

New Member
Joined
Jul 19, 2021
Messages
9
Office Version
  1. 2013
Platform
  1. Windows
So I have this folder structure.
1627210331468.png


The MainFolder (let’s call it level 0) has any number of folders (Folder1, Folder2…). The names are not in any sequence.

At level 1 (i.e. inside each folder) there is a ‘summary’ DTA file (xyz.DTA) in the case shown but the name of this file changes randomly across folders. At level1 there is also a subfolder (SUBFOLDER). This subfolder has the same name in all the other folders.

At level2 there is are two more DTA files (CHARGE.DTA and DISCHARGE.DTA). Again these names are consistent in the other folders too.

The DTA files are basically text files that are tab delimited.

I want to combine all the summary files (the ones at level1) in parallel. And I want to do the same with the CHARGE files and the DISCHARGE files.

I am looking into how to loop through subfolders but if anyone knows a similar problem that I can appropriate for my needs that could save time.

Thanks in Advance.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
To clarify: I want to combine all the summary files in parallel in one worksheet. All the CHARGE files (again in parallel) in a second worksheet. And all the DISCHARGE files (once again in parallel) in a third worksheet.
 
Upvote 0
As they are many samples whatever the Excel forum to scan subfolders …​
Or zip a root folder structure with some samples text files including in the root folder (MainFolder) the expected workbook result​
saved as .xlsb binary format according to the samples text files then link the zip file on a files host website like Dropbox …​
 
Upvote 0
As they are many samples whatever the Excel forum to scan subfolders …​
Or zip a root folder structure with some samples text files including in the root folder (MainFolder) the expected workbook result​
saved as .xlsb binary format according to the samples text files then link the zip file on a files host website like Dropbox …​

I've uploaded the samples and the 'Desired Output' here on Google Drive.
 
Upvote 0
I've figured it out (though the code is clunky and not suitable to post here)

I guess this is redundant now but I can't find the delete option
 
Upvote 0
According to your attachment a VBA demonstration for starters, the workbook must be saved in the main folder :​
VBA Code:
Sub TextImport(P$, ByVal F$, S&)
     Dim C%
         F = Dir$(P & F):  If F = "" Then Exit Sub
         C = Worksheets(S).UsedRange.Columns.Count
    With Worksheets(S).QueryTables.Add("TEXT;" & P & F, Worksheets(S).Cells(C - (C > 1)))
        .AdjustColumnWidth = True
        .RefreshStyle = xlOverwriteCells
        .TextFileDecimalSeparator = "."
        .TextFileParseType = xlDelimited
        .TextFileTabDelimiter = True
        .TextFileTextQualifier = xlTextQualifierNone
        .Refresh False:  .Delete
    End With
End Sub

Sub Demo1()
    Dim Obj As Object, P$
        For Each Obj In Worksheets:  Obj.UsedRange.Clear:  Next
        Application.ScreenUpdating = False
    For Each Obj In CreateObject("Scripting.FileSystemObject").GetFolder(ThisWorkbook.Path).SubFolders
         P = Obj.Path & "\"
         TextImport P, "*.DTA", 1
         P = P & "CHARGE_DISCHARGE\"
         TextImport P, "CHARGE_#1.DTA", 2
         TextImport P, "DISCHARGE_#1.DTA", 3
    Next
        Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top