Public Sub NonRecursiveMethod()
Application.ScreenUpdating = False
Dim fso, oFolder, oSubfolder, oFile, queue As Collection, MyFolder As String
Dim wsDest As Worksheet, wkbSource As Workbook, lCol As Long, lRow As Long
Dim splt As Variant, FN As String, wbName As String, x As Long: x = 1
Set wsDest = ThisWorkbook.Sheets("Sheet1")
Set fso = CreateObject("Scripting.FileSystemObject")
Set queue = New Collection
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Please select a folder"
.Show
.AllowMultiSelect = False
If .SelectedItems.Count = 0 Then
MsgBox "You did not select a folder."
Exit Sub
End If
MyFolder = .SelectedItems(1) & "\"
End With
queue.Add fso.GetFolder(MyFolder)
Do While queue.Count > 0
Set oFolder = queue(1)
queue.Remove 1
For Each oSubfolder In oFolder.SubFolders
queue.Add oSubfolder
Next oSubfolder
For Each oFile In oFolder.Files
If Right(oFile, 4) Like "xls*" Then
Set wkbSource = Workbooks.Open(oFile)
splt = Split(oFile, "\")
FN = splt(UBound(splt) - 1)
wbName = Split(wkbSource.Name, ".")(0)
If Not IsError(Evaluate("=ISREF('[" & oFile.Name & "]" & "EntryList" & "'!$A$1)")) Then
With Sheets("EntryList")
If x = 1 Then
lCol = .Cells(1, Columns.Count).End(xlToLeft).Column
wsDest.Range("A1") = "NurseryName"
.Range("A1").Resize(, lCol).Copy wsDest.Range("B1")
x = x + 1
lRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Range("A25").Resize(lRow - 24, lCol).Copy wsDest.Range("B2")
wsDest.Range("A2").Resize(lRow - 24) = FN & "-" & wbName
Else
lRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
lCol = .Cells(25, Columns.Count).End(xlToLeft).Column
.Range("A25").Resize(lRow - 24, lCol).Copy wsDest.Cells(wsDest.Rows.Count, "B").End(xlUp).Offset(1)
wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Resize(lRow - 24) = FN & "-" & wbName
End If
End With
End If
wkbSource.Close False
End If
Next oFile
Loop
Application.ScreenUpdating = True
End Sub