• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copying Data from Multiple workbooks to master Workbook

srinidhi

Active Member
In a folder called Timesheet I have 2 folders named 01-15 & 16-30, there are 20 workbooks in each folder. I want to copy only 2 cells namely E&F (E&F are merged) 5 & F 25 to master sheet. The challenge is both the folders contains the same set of names, so from folder 16-30 I just want to copy F 25 to master sheet. Please let me know the steps or the macro code for this.


Thanking you in advance for helping me solve this hectic task.
 
[pre]Private FSO As Object
Private NextRow As Long

Sub LoopFolders()

Set FSO = CreateObject("Scripting.FileSystemObject")

selectFiles "c:MyTest", ThisWorkbook '<<<< change as required

Set FSO = Nothing

End Sub

'---------------------------------------------------------------------------
Sub selectFiles(ByVal sPath As String, ByRef wb As Workbook)
'---------------------------------------------------------------------------
Dim This As Workbook
Dim folder As Object
Dim files As Object
Dim file As Object
Dim fldr As Object
Dim subfldr As Object

Set folder = FSO.GetFolder(sPath)

For Each fldr In folder.Subfolders
selectFiles fldr.Path, wb
Next fldr

For Each file In folder.files

If file.Type Like "Microsoft*Excel*Worksheet*" Then

Set This = Workbooks.Open(Filename:=file.Path)
NextRow = NextRow + 1
This.Worksheets(1).Range("E25:F25").Copy wb.Worksheets(1).Cells(NextRow, "A")
This.Close SaveChanges:=False
End If
Next file
End Sub[/pre]
 
Back
Top