I have 3 files in a folder and one master template.
I want to:
- Loop through these files then copy the content to a master file.
- Each WHOLE file will be pasted to a new worksheet in the master file.
- The new worksheet's name will be the same as file's name.
The codes below are not working and missing functions 2 and 3.
Sub AllFiles()
Application.EnableCancelKey = xlDisabled
Dim folderPath As String
Dim Filename As String
Dim wb As Workbook
Dim sh As Worksheet
folderPath = "C:\Users\Ryan\Desktop\LoopThroughFolders\Sample1\" 'contains folder path
If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"
Filename = Dir(folderPath & "*.xlsx")
Do While Filename <> ""
Application.ScreenUpdating = False
Set wb = Workbooks.Open(folderPath & Filename)
Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Copy
'Not working well here as it will be overwritten by the next file
Workbooks("Master Template").Worksheets("Sheet1").Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row + 1).PasteSpecial xlPasteValues
Workbooks(Filename).Close
Filename = Dir
Loop
Application.ScreenUpdating = True
End sub