Sub XYZ()
Dim sh As Worksheet, shDelete, arr(), sRow&, i&, tmp$
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set sh = Sheets("DK_TS")
i = sh.Range("U100000").End(xlUp).Row
If i < 10 Then Exit Sub
arr = sh.Range("A10:V" & i).Value
tmp = "|"
sRow = UBound(arr)
Call DeleteSheet(shDelete, Sheets("DK_TS").Name)
For i = 1 To sRow
If arr(i, 21) <> "" Then
If InStr(1, tmp, "|" & arr(i, 21) & "|", vbTextCompare) = 0 Then
tmp = tmp & arr(i, 21) & "|"
Call AddSheet(sh, sRow, arr, arr(i, 21))
End If
End If
Next i
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "Da tach xong"
End Sub
Private Sub DeleteSheet(shDelete, ByVal shName$)
For Each shDelete In ThisWorkbook.Worksheets
If shDelete.Name <> shName Then shDelete.Delete
Next shDelete
End Sub
Private Sub AddSheet(sh, sRow&, ByVal res, ByVal lop As String)
Dim i&, k&, j&
sh.Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = lop
ActiveSheet.Shapes("Rounded Rectangle 3").Delete
For i = 1 To sRow
If res(i, 21) = lop Then
k = k + 1
res(k, 1) = k
For j = 2 To UBound(res, 2)
res(k, j) = res(i, j)
Next j
End If
Next i
If k < sRow Then Range("A10").Resize(sRow - k).EntireRow.Delete
Range("A10").Resize(k, UBound(res, 2)) = res
End Sub