Em chào các anh. chị. Em có báo cáo đổ tự động của Nhà cung cấp theo ngày của 1 tháng (từ ngày 01 đến ngày 30) như mẫu. Mỗi ngày là 1 file excell khác nhau rất khó cho việc đối chiếu số liệu tổng của tháng. Mẫu biểu của các file này giống nhau, chỉ khác số liệu từng ngày. Giờ em muốn gom các file excell thành 1 sheet duy nhất (giống như file "BANG TONG HOP"). Anh /Chị chỉ dùm em ạ. em cảm ơn
Sub MergeSheets()
Dim SrcBook As Workbook
Dim FirstFile As Boolean
Dim fso As Object, f As Object, ff As Object, f1 As Object
Dim path As String
path = InputBox("Enter the file path of Excel Files to merge", "Enter the folder path")
Application.ScreenUpdating = False
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.Getfolder(path & "\")
Sheet1.Range("A1").CurrentRegion.Offset(1, 0).Clear
Set ff = f.Files
FirstFile = False
For Each f1 In ff
Set SrcBook = Workbooks.Open(f1)
If FirstFile = False Then
Range("A2:IV" & Range("A65536").End(xlUp).Row).Copy
FirstFile = True
Else
Range("A2:IV" & Range("A65536").End(xlUp).Row).Copy
End If
ThisWorkbook.Worksheets(1).Activate
Range("A1000000").End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
SrcBook.Close SaveChanges:=fales
Next
Application.ScreenUpdating = True
End Sub
Bạn tùy chọn vùng dữ liệu của bạn theo code này. Nếu muốn dùng ADO thì xem file đính kèm. Nhớ thay đổi code theo dữ liệu của bạn