Sub ThayTheVlookup()
Dim DuLieuTam
Dim LastRow As Long, DongCuoiB As Long, DongCuoiG As Long, i As Integer
Const SoDongCuoi = 50
For i = 1 To 2 'file thuc tê' có den 20 sheet
With Sheets(i)
DongCuoiB = Cells(SoDongCuoi, 2).End(xlUp).Row
DongCuoiG = Cells(SoDongCuoi, 7).End(xlUp).Row
If DongCuoiB > DongCuoiG Then
LastRow = DongCuoiB
Else: LastRow = DongCuoiG
End If
If LastRow < 3 Then Exit Sub
Dim VungKetQua As Range
Set VungKetQua = .Range("A3:I" & LastRow)
DuLieuTam = VungKetQua
End With
With DanhSach
LastRow = .Range("B" & Rows.Count).End(xlUp).Row
If LastRow < 2 Then Exit Sub
Dim x As Long, y As Long
Dim rngData As Range, rngFind As Range
Set rngData = .Range("A1:D" & LastRow)
End With
For x = 1 To UBound(DuLieuTam)
Set rngFind = rngData.Find(What:=DuLieuTam(x, 2), LookIn:=xlFormulas, LookAt:=xlWhole)
DuLieuTam(x, 1) = x
DuLieuTam(x, 3) = rngFind.Offset(, 1)
DuLieuTam(x, 4) = rngFind.Offset(, 2)
Next x
For y = 1 To UBound(DuLieuTam)
Set rngFind = rngData.Find(What:=DuLieuTam(y, 7), LookIn:=xlFormulas, LookAt:=xlWhole)
DuLieuTam(y, 6) = y
DuLieuTam(y, 8) = rngFind.Offset(, 1)
DuLieuTam(y, 9) = rngFind.Offset(, 2)
Next y
VungKetQua = DuLieuTam
Next i
End Sub