Hello terriertrip,
The problem was not the subfolders. It was the data was overwriting itself.
This macro solves the problem and works much faster since no workbook is being opened to parse the data.
Sub Consolidate2()
Dim ByteData() As Byte
Dim cnt As Long
Dim FISdata As String
Dim Fs As Object 'FileSystem
Dim d As Object 'Folder
Dim Fx As Object 'Subfolder
Dim file As Object 'File
Dim Headers As Variant
Dim n As Long
Dim iRow As Long 'next available row index of destination worksheet
Dim Text As String
Dim wsMaster As Worksheet
iRow = 2
Set wsMaster = ThisWorkbook.Sheets("Master") 'sheet data will be compiled into
n = wsMaster.Cells(Rows.Count, "A").End(xlUp).Row
If n > iRow Then iRow = n + 1
Set Fs = CreateObject("Scripting.FileSystemObject")
Set d = Fs.GetFolder("Z:\Operations\Chupacabra\Data\")
For Each Fx In d.Subfolders 'loop through subfolders
For Each file In Fx.Files 'loop through files
If file.Name Like "*dq1000d.las*" Then
Open file.Path For Binary Access Read As #1
ReDim ByteData(LOF(1))
Get #1, , ByteData
Close #1
Text = StrConv(ByteData, vbUnicode)
Lines = Split(Text, vbCrLf)
cnt = 0
ReDim Headers(2)
For n = 0 To UBound(Lines) - 1
If Left(Lines(n), 6) = "COMP. " Then Headers(0) = Lines(n): cnt = cnt + 1
If Left(Lines(n), 6) = "WELL. " Then Headers(1) = Lines(n): cnt = cnt + 1
If Left(Lines(n), 5) = "API. " Then Headers(2) = Lines(n): cnt = cnt + 1
If cnt = 3 Then Exit For
Next n
n = InStrRev(Text, "~Ascii FIS DATA") + 17
FISdata = Mid(Text, n, Len(Text) - n)
Lines = Split(FISdata, vbCrLf)
wsMaster.Range("B" & iRow).Resize(1, 3).Value = Headers
iRow = iRow + 1
Lines = Application.Transpose(Lines)
wsMaster.Range("A" & iRow).Resize(UBound(Lines), 1).Value = Lines
iRow = iRow + UBound(Lines) - 1
End If
Next file
Next Fx
End Sub
Bookmarks