Option Explicit
Public Sub Gpe()
Dim sArr(), dArr(1 To 1000, 1 To 4), SP As String
Dim I As Long, K As Long, R As Long, fDay As Long, eDay As Long
With Sheets("NXT")
fDay = .Range("B2").Value
eDay = .Range("B3").Value
SP = .Range("B4").Value
'============================= Nhap'
sArr = Sheets("Nhap").Range("A4", Sheets("Nhap").Range("A10000").End(xlUp)).Resize(, 4).Value
R = UBound(sArr)
If R > 1 Then
For I = 2 To R
If sArr(I, 1) >= fDay Then
If sArr(I, 1) <= eDay Then
If sArr(I, 2) = SP Then
K = K + 1
dArr(K, 1) = sArr(I, 1)
dArr(K, 2) = sArr(I, 3)
dArr(K, 3) = sArr(I, 4)
End If
End If
End If
Next I
End If
'============================= Xuat'
sArr = Sheets("Xuat").Range("A4", Sheets("Xuat").Range("A10000").End(xlUp)).Resize(, 4).Value
R = UBound(sArr)
If R > 1 Then
For I = 2 To R
If sArr(I, 1) >= fDay Then
If sArr(I, 1) <= eDay Then
If sArr(I, 2) = SP Then
K = K + 1
dArr(K, 1) = sArr(I, 1)
dArr(K, 2) = sArr(I, 3)
dArr(K, 4) = sArr(I, 4)
End If
End If
End If
Next I
End If
'======================================NXT'
.Range("A7:D1000").ClearContents
.Range("A7:D1000").Borders.LineStyle = 0
If K Then
.Range("A7:D7").Resize(K) = dArr
.Range("A7:D7").Resize(K).Borders.LineStyle = 1
.Range("A7:D7").Resize(K).Sort Key1:=.Range("A7"), Order1:=xlAscending
End If
End With
End Sub