Mình được bạn quanluu1989 trợ giúp đoạn code sau:
Sub test()
Dim FSO As Object, FileItem As Object, i As Integer, wbmain As Workbook, wb As Workbook
Set wbmain = ThisWorkbook
Set FSO = CreateObject("Scripting.FileSystemObject")
With wbmain
For Each FileItem In FSO.GetFolder(wbmain.Path).Files
If FileItem.Name <> "Tong Hop.xlsx" And Left(FileItem.Name, 1) <> "~" Then
i = i + 1
Set wb = Workbooks.Open(FileItem.Path)
wb.Sheets("Max").Range("D2:E34").Copy
.ActiveSheet.Cells(4, i * 2).PasteSpecial xlPasteValues
.ActiveSheet.Cells(2, i * 2) = Left(FileItem.Name, Len(FileItem.Name) - 5)
wb.Close False
End If
Next
End With
End Sub
Đoạn code này dùng để copy dữ liệu từ các file excel khác nhau về file tổng hợp. Mình muốn hỏi:
1. Hiện giờ đoạn code này tự động lấy dữ liệu tại sheet max trong tất cả các file excel nhưng giờ mình muốn tự add file excel để lấy dữ liệu trong sheet max thì phải sửa code như thế nào?
2. Đoạn code trên đang copy dữ liệu rồi paste vào file tổng hợp bắt đầu từ cột B, mình muốn paste vào file tổng hợp từ cột C hay D thì sửa như thế nào?
Chân thành cảm ơn các bạn!
Sub test()
Dim FSO As Object, FileItem As Object, i As Integer, wbmain As Workbook, wb As Workbook
Set wbmain = ThisWorkbook
Set FSO = CreateObject("Scripting.FileSystemObject")
With wbmain
For Each FileItem In FSO.GetFolder(wbmain.Path).Files
If FileItem.Name <> "Tong Hop.xlsx" And Left(FileItem.Name, 1) <> "~" Then
i = i + 1
Set wb = Workbooks.Open(FileItem.Path)
wb.Sheets("Max").Range("D2:E34").Copy
.ActiveSheet.Cells(4, i * 2).PasteSpecial xlPasteValues
.ActiveSheet.Cells(2, i * 2) = Left(FileItem.Name, Len(FileItem.Name) - 5)
wb.Close False
End If
Next
End With
End Sub
Đoạn code này dùng để copy dữ liệu từ các file excel khác nhau về file tổng hợp. Mình muốn hỏi:
1. Hiện giờ đoạn code này tự động lấy dữ liệu tại sheet max trong tất cả các file excel nhưng giờ mình muốn tự add file excel để lấy dữ liệu trong sheet max thì phải sửa code như thế nào?
2. Đoạn code trên đang copy dữ liệu rồi paste vào file tổng hợp bắt đầu từ cột B, mình muốn paste vào file tổng hợp từ cột C hay D thì sửa như thế nào?
Chân thành cảm ơn các bạn!