Option Explicit
Sub TapCode_TinhTon()
Dim NhapXuat As Variant, Ton As Variant, I As Long, K As Long
Dim WF As WorksheetFunction
Set WF = WorksheetFunction
With Sheet1
I = .UsedRange.SpecialCells(xlCellTypeLastCell).Row
If I < 7 Then MsgBox "Khong co du lieu nhap-xuat!", vbCritical + vbOKOnly, "Thong bao"
NhapXuat = .Range("D7:F" & I).Value
ReDim Ton(1 To UBound(NhapXuat, 1), 1 To 1)
For I = 1 To UBound(NhapXuat, 1)
Ton(I, 1) = WF.Sum(.Range("D7:D" & I + 6)) - WF.Sum(.Range("E7:E" & I + 6))
Next I
.Range("F7").Resize(UBound(NhapXuat, 1)).Value = Ton
End With
End Sub