Sub GenericMasterByDateModified_1018932()
Application.ScreenUpdating = False
Dim wb As Workbook, wb2 As Workbook
Dim FolderName As String
Dim NextRow As Long, NextColumn As Long
Dim ws As Worksheet
Dim fso As Object, objFiles As Object, obj As Object
Dim kount As Long, i As Long, j As Long
Dim arr As Variant
Dim x As Long, y As Long
Dim Txt1 As Date, Txt2 As Date, Txt3 As String, Txt4 As String
''''Select folder that contains files
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show = 0 Then Exit Sub
FolderName = .SelectedItems(1) & "\"
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFiles = fso.GetFolder(FolderName).Files
kount = objFiles.Count
''''Loop through files and populate array with file name and date last modified
ReDim arr(1 To kount, 1 To 2)
i = 1
For Each obj In objFiles
arr(i, 1) = obj.Name
arr(i, 2) = obj.datelastmodified
i = i + 1
Next obj
''''Sort array by date last modified (Descending)
For x = LBound(arr) To UBound(arr)
For y = x To UBound(arr)
If arr(y, 2) > arr(x, 2) Then 'Change ">" to "<" for Ascending sort
Txt1 = arr(x, 2)
Txt2 = arr(y, 2)
Txt3 = arr(x, 1)
Txt4 = arr(y, 1)
arr(x, 2) = Txt2
arr(y, 2) = Txt1
arr(x, 1) = Txt4
arr(y, 1) = Txt3
End If
Next y
Next x
Set wb = Workbooks.Add
''''Loop through files in order of array
For x = LBound(arr) To UBound(arr)
Set wb2 = Workbooks.Open(FolderName & arr(x, 1))
''''Loop through sheets
For Each ws In wb2.Worksheets
NextColumn = wb.Sheets(1).Cells(1, Columns.Count).End(xlToLeft).Column + 1
ws.UsedRange.Copy Destination:=wb.Sheets(1).Cells(1, NextColumn)
Next ws
wb2.Close savechanges:=False
Next x
Application.ScreenUpdating = True
MsgBox "The dishes are done, dude!"
End Sub