Sub GPE()
Dim Darr, Arr(), Nban As String, i As Long, j As Integer, k As Integer, tmp As String
With Sheets(1)
Darr = .Range("A2:I" & .Range("B65500").End(xlUp).Row + 1)
End With
ReDim Arr(1 To UBound(Darr), 1 To 8)
With Sheets(2)
Nban = .Range("A1")
For i = 1 To UBound(Darr) - 1
If Darr(i + 1, 1) = "" Then Darr(i + 1, 1) = Darr(i, 1)
If Darr(i, 9) = Nban And Darr(i, 7) <> "XS1" And Darr(i, 7) <> "XS9" Then
k = k + 1
For j = 2 To 8
Arr(k, j) = Darr(i, j)
Next j
If tmp <> Darr(i, 1) Then
Arr(k, 1) = Darr(i, 1)
tmp = Darr(i, 1)
End If
End If
Next i
If k = 0 Then
MsgBox "Khong co du lieu nguoi ban " & Nban & " co xuat su XS1 va XS9"
Exit Sub
End If
.Range("A2:H20000").ClearContents
.Range("A2").Resize(k, 8) = Arr
End With
End Sub