Tôi có file đính kèm, Muốn copy dữ liệu từ các file paste Transport sang file tổng hợp, tôi có code nhưng nó paste theo hàng dọc, mọi người có thể sửa code này cho nó dán theo hàng ngang được không ạ, xin chân thành cảm ơn!
Sub Button1_Click()
Dim basebook As Workbook
Dim mybook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim n As Long, rNum As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant
SaveDriveDir = CurDir
MyPath = "D:\TXT\"
ChDrive MyPath
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls*), *.xls*", MultiSelect:=True)
If IsArray(FName) Then
Set basebook = ActiveWorkbook
rNum = 1
'Xoa du lieu cu
Sheets("THCS").Range("b9:b38").ClearContents
Sheets("THCS").Range("d9:f38").ClearContents
Sheets("THCS").Range("h9:k38").ClearContents
For n = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(n))
'Tong hop TH Lop,HS,CBGVNv
Set sourceRange = mybook.Worksheets("Truong").Range("d4")
rNum = (n - 1) * sourceRange.Rows.Count + 9
'Xac dinh o de copy
With sourceRange
Set destrange = basebook.Worksheets("THCS").Cells(rNum, "b").Resize(.Rows.Count, .Columns.Count)
End With
destrange.Value = sourceRange.Value
'-----------
Set sourceRange = mybook.Worksheets("BCao nhanh").Range("f106:f108")
rNum = (n - 1) * sourceRange.Rows.Count + 9
'Xac dinh o de copy
With sourceRange
Set destrange = basebook.Worksheets("THCS").Cells(rNum, "d").Resize(.Rows.Count, .Columns.Count)
End With
destrange.Value = sourceRange.Value
'--------------
Set sourceRange = mybook.Worksheets("BCao nhanh").Range("f111:f114")
rNum = (n - 1) * sourceRange.Rows.Count + 9
'Xac dinh o de copy
With sourceRange
Set destrange = basebook.Worksheets("THCS").Cells(rNum, "h").Resize(.Rows.Count, .Columns.Count)
End With
destrange.Value = sourceRange.Value
mybook.Close False
Next n
End If
'Tra ve mac dinh truoc khi mo
ChDrive SaveDriveDir
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
Mong các Pro chỉnh code này cho nó dán theo hàng ngang với ạ