Sub NhatKiChung_()
Application.ScreenUpdating = False
With Sheets("data_tong")
.AutoFilterMode = False
endR = .Cells(65000, 1).End(3).Row ' den dong thu 65k, cot thu 1
arr = .Range("D16:N65000" & endR).Value ' vung tham chieu
End With
With Sheets("nkc")
.Rows("14:1000").EntireRow.Hidden = False ' an tu dong
.Range("A14:G1000").ClearContents ' xoa tu dong
.[F11] = 0: .[G11] = 0
fD = CLng(.[I3]): eD = CLng(.[I5]) ' dieu kien ngay
End With
s = 0: SoDu = 0
ReDim ArrKQ(1 To 1000, 1 To 7) ' vung chua ket qua
For i = 1 To UBound(arr)
If CLng(arr(i, cNg)) >= fD Then
If CLng(arr(i, cNg)) <= eD Then ' neu cot ngay thang o so nkc <= ngay thang so chi tiet sau do
s = s + 1 ' ke tiep 1 dong
For k = 1 To 4 ' tu cot ngay thang den cot dien giai
ArrKQ(s, k) = arr(i, k + 0) ' tinh tu cot dau tien tren so nkc, lay ra cot bao nhieu tai sheet chi tiet
Next k
ArrKQ(s, 5) = arr(i, cTkCo) ' so chi tiet tk doi ung tuong ung cot tk co so nkc
ArrKQ(s, 6) = arr(i, cST) 'ST PS No ' so tiet ben co cua so chi tiet = so tien cua so nkc
s = s + 1
For k = 1 To 4 ' tu cot ngay thang den cot dien giai
ArrKQ(s, k) = arr(i, k + 0) ' tinh tu cot dau tien tren so nkc, lay ra cot bao nhieu tai sheet chi tiet
Next k
ArrKQ(s, 5) = arr(i, cTkNo)
ArrKQ(s, 7) = arr(i, cST) 'STPS Co
End If
End If
Next i
If s = 0 Then
With Sheets("nkc") ' an dong khi khong co ket qua
.Rows(s + 14 & ":1000").Hidden = True ' an dong khi khong co ket qua
End With ' an dong khi khong co ket qua
MsgBox "Không có"
GoTo Exit_Sub
End If
With Sheets("nkc")
.Rows(s + 14 & ":1000").EntireRow.Hidden = True
If SoDu > 0 Then
.[F11] = SoDu: .[G11] = 0
Else
.[G11] = -SoDu: .[F11] = 0
End If
'.Range("A11:G200").ClearContents
.[A14].Resize(s, 7) = ArrKQ
End With
Exit_Sub:
Application.ScreenUpdating = True
End Sub