Option Explicit
Sub exa()
Dim _
wksDestination As Worksheet, _
wks As Worksheet, _
wbSource As Workbook, _
aryTmp As Variant, _
rngLRow As Range, _
rngLCol As Range, _
rngLCell As Range, _
rngData As Range, _
rngDest As Range, _
FSO As Object, _
fsoFolder As Object, _
fsoFile As Object
Application.ScreenUpdating = False
Set wksDestination = ThisWorkbook.Worksheets("Destination")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fsoFolder = FSO.GetFolder(ThisWorkbook.Path)
For Each fsoFile In fsoFolder.Files
If fsoFile.Path <> ThisWorkbook.FullName _
And Mid(fsoFile.Name, InStrRev(fsoFile.Name, ".")) = ".xls" Then
Set wbSource = Workbooks.Open(fsoFile.Path, , True)
For Each wks In wbSource.Worksheets
Set rngLRow = RangeFound(SearchRange:=Range(wks.Cells(2, 1), _
wks.Cells(wks.Rows.Count, wks.Columns.Count)) _
)
If Not rngLRow Is Nothing Then
Set rngLCol = _
RangeFound(SearchRange:=Range(wks.Cells(2, 1), _
wks.Cells(wks.Rows.Count, wks.Columns.Count)), _
SearchRowCol:=xlByColumns)
Set rngLCell = Application.Intersect(wks.Rows(rngLRow.Row), wks.Columns(rngLCol.Column))
aryTmp = Range(wks.Cells(2, 1), rngLCell).Value2
With wksDestination
Set rngDest = RangeFound(Range(.Cells(2, 1), .Cells(.Rows.Count, .Columns.Count)))
End With
If rngDest Is Nothing Then
Set rngDest = wksDestination.Cells(2, 1)
Else
Set rngDest = wksDestination.Cells(rngDest.Row + 1, 1)
End If
If Not UBound(aryTmp, 1) + rngDest.Row > rngDest.Parent.Rows.Count Then
rngDest.Resize(UBound(aryTmp, 1), UBound(aryTmp, 2)).Value = aryTmp
Else
MsgBox "Sorry, sheet is full", vbInformation, vbNullString
wbSource.Close False
Application.ScreenUpdating = True
Exit Sub
End If
End If
Next
wbSource.Close False
End If
Next
Application.ScreenUpdating = True
End Sub
Function RangeFound(SearchRange As Range, _
Optional FindWhat As String = "*", _
Optional StartingAfter As Range, _
Optional LookAtTextOrFormula As XlFindLookIn = xlValues, _
Optional LookAtWholeOrPart As XlLookAt = xlPart, _
Optional SearchRowCol As XlSearchOrder = xlByRows, _
Optional SearchUpDn As XlSearchDirection = xlPrevious, _
Optional bMatchCase As Boolean = False) As Range
If StartingAfter Is Nothing Then
Set StartingAfter = SearchRange(1)
End If
Set RangeFound = SearchRange.Find(What:=FindWhat, _
After:=StartingAfter, _
LookIn:=LookAtTextOrFormula, _
LookAt:=LookAtWholeOrPart, _
SearchOrder:=SearchRowCol, _
SearchDirection:=SearchUpDn, _
MatchCase:=bMatchCase)
End Function