Hi Simi,
Try this:
Code:
Sub TestMe()
Dim sFolder As String
Application.ScreenUpdating = False
sFolder = "D:\My Documents\Test\"
Call Consolidate(sFolder, ThisWorkbook)
End Sub
Private Sub Consolidate(strFolder As String, wbMaster As Workbook)
'Author : Ken Puls (www.excelguru.ca)
'Function purpose: Consolidate data
Dim wbTarget As Workbook
Dim objFso As Object
Dim objFiles As Object
Dim objSubFolder As Object
Dim objSubFolders As Object
Dim objFile As Object
Dim ary(3) As Variant
Dim lRow As Long
'Set Error Handling
On Error GoTo EarlyExit
'Create objects to enumerate files and folders
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFiles = objFso.getfolder(strFolder).Files
Set objSubFolders = objFso.getfolder(strFolder).subFolders
'Loop through each file in the folder
For Each objFile In objFiles
If InStr(1, objFile.Path, ".xls") > 0 Then
Set wbTarget = Workbooks.Open(objFile.Path)
With wbTarget.Worksheets(1)
ary(0) = .Range("A1")
ary(1) = .Range("A2")
ary(2) = .Range("A10")
ary(3) = .Range("A11")
End With
With wbMaster.Worksheets(1)
lRow = .Range("A" & .Rows.Count).End(xlUp).Offset(1, 0).Row
.Range("A" & lRow & ":D" & lRow) = ary
End With
wbTarget.Close savechanges:=False
End If
Next objFile
'Request count of files in subfolders
For Each objSubFolder In objSubFolders
Consolidate objSubFolder.Path, wbMaster
Next objSubFolder
EarlyExit:
'Clean up
On Error Resume Next
Set objFile = Nothing
Set objFiles = Nothing
Set objFso = Nothing
On Error GoTo 0
End Sub
Bookmarks