Thầy cho em hỏi, em viết code để nhập dữ liệu từ work book3 vào work book 4 khi chạy thì ra sai KQ, không biết có bị thiếu chỗ nào ko ạ?
Dim dongcuoi_wb3 As Long
dongcuoi_wb3 = Workbooks("Book3").Sheets("sheet1").Range("A" & Rows.Count).End(xlUp).Row
Dim dongdau_wb3 As Long
dongdau_wb3 = 2
Dim khoangcach_wb3 As Long
khoangcach_wb3 = dongcuoi_wb3 - dongdau_wb3
Workbooks("Book4").Sheets("Data").Range("A" & dongcuoi_wb4 + 1 & ":C" & dongcuoi_wb4 + khoangcach_wb3).Value = _
Workbooks("Book3").Sheets("Sheet1").Range("A" & dongdau_wb3 & ":C" & dongcuoi_wb3).Value
Chào bạn mình đẩy code mẫu lên nhé.
Option Explicit
Sub Luu_DuLieu()
'Thu muc chon file
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = True 'cho phep chon nhieu file
.Show 'Hien cua so chon file
Dim i As Integer
For i = 1 To .SelectedItems.Count
'Xet file duoc chon
Dim wb_KQ As Workbook 'Bien workbook ket qua (Bang luong tong hop)
Dim wb_1 As Workbook 'Bien workbook duoc chon tu thu muc (Tung file bang luong chi tiet)
Set wb_KQ = ThisWorkbook
Set wb_1 = Workbooks.Open(.SelectedItems(i))
'B1: xac dinh dong cuoi bang tong hop (Bang luong tong hop)
Dim DongCuoi_KQ As Long
DongCuoi_KQ = wb_KQ.Sheets("Data_TienLuong").Range("A" & Rows.Count).End(xlUp).Row
'B2: xac dinh dong dau va dong cuoi bang chi tiet (Tung file bang luong chi tiet)
Dim DongDau_CT As Long
DongDau_CT = 8
Dim DongCuoi_CT As Long
DongCuoi_CT = wb_1.Sheets(1).Range("F" & Rows.Count).End(xlUp).Row
'B3: xac dinh khoang cach
Dim KhoangCach As Long
KhoangCach = DongCuoi_CT - DongDau_CT + 1
'B4: luu
wb_KQ.Sheets("Data_TienLuong").Range("A" & DongCuoi_KQ + 1 & ":BM" & DongCuoi_KQ + KhoangCach).Value = _
wb_1.Sheets(1).Range("A" & DongDau_CT & ":BM" & DongCuoi_CT).Value
'B5: Dong file noi dung
wb_1.Close SaveChanges:=False
Next i
End With
End Sub