Sub RunMeFirst()
Application.ScreenUpdating = False
Dim FileSystem As Object, HostFolder As String
HostFolder = "C:\Test\"
Set FileSystem = CreateObject("Scripting.FileSystemObject")
CopyData FileSystem.GetFolder(HostFolder)
Application.ScreenUpdating = True
End Sub
Sub CopyData(Folder)
Application.ScreenUpdating = False
Dim FSO As Object, fld As Object, fsoFile As Object, fsoFol As Object, folderPath As String, srcWB As Workbook
Dim wsDest As Worksheet, wsSource As Worksheet, i As Long, v As Variant, arr() As Variant, cnt As Long, SubFolder, File
Set wsDest = ThisWorkbook.Sheets("Sheet1")
With wsDest
.Range("A2:M" & .Cells(.Rows.Count, "A").End(xlDown).Row).ClearContents
End With
For Each SubFolder In Folder.SubFolders
CopyData SubFolder
Next SubFolder
For Each File In Folder.Files
If File.Name Like "600*.xlsx" Then 'change the file name to match the name of your source file
Set srcWB = Workbooks.Open(Filename:=File)
With ActiveWorkbook
Set wsSource = .Sheets(1)
v = wsSource.Range("D5:D13").Value
For i = LBound(v) To UBound(v)
If v(i, 1) <> "" Then
cnt = cnt + 1
ReDim Preserve arr(1 To cnt)
arr(cnt) = v(i, 1)
End If
Next i
With wsDest
.Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(, 5).Value = arr
.Cells(.Rows.Count, "F").End(xlUp).Offset(1).Resize(, 7).Value = Application.Transpose(wsSource.Range("P9:P15"))
.Cells(.Rows.Count, "M").End(xlUp).Offset(1).Value = wsSource.Range("O16").Value
End With
cnt = 0
.Close savechanges:=False
End With
End If
Next File
Application.ScreenUpdating = True
End Sub