Hello,
I need to copy all the files in the same folder and paste to a combined file.
However, it's always the case that the first files in the folder are not copied fully.
For example, in a folder with 50 files.
File 1 has 2000 lines, and only 500 lines are copied.
File 2 has 3000 lines, and only 300 lines are copied.
...
File 7 has 1000 lines, and only 10 lines are copied.
The rest, from file 8- 50 are okie (although some files not 100% of the lines are copied).
Could you help me to understand why the below code always have problem for the first several files in the folder?
Really appreciate your help!
Chau
=======================================================================================
=================================================Sub simpleXlsMerger() Dim bookList As Workbook Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object Application.ScreenUpdating = False Set mergeObj = CreateObject("Scripting.FileSystemObject") Set dirObj = mergeObj.Getfolder("O:\Entrepot\Group\Whse\CHAU\Combine files into 1 sheet\PUROLATOR") Set filesObj = dirObj.Files For Each everyObj In filesObj Set bookList = Workbooks.Open(everyObj) Dim sht As Worksheet Set sht = ThisWorkbook.Worksheets("Combined") Dim LastRow As Long LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row Range("A2:GF" & LastRow).Copy ThisWorkbook.Worksheets(1).Activate Range("A500000").End(xlUp).Offset(1, 0).PasteSpecial Application.CutCopyMode = False bookList.Close Next End Sub
Bookmarks