Option Explicit
'By ChaoQuay
Sub Tach_Sheets()
Dim Lr&, i&, j&, k&, C&, Arr()
Dim dic As Object, Key$, Ws As Worksheet, Rng As Range
Set dic = CreateObject("Scripting.Dictionary")
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For Each Ws In Worksheets
If Ws.Name <> "TH" Then
Ws.Delete
End If
Next Ws
With Sheets("TH")
C = .Range("B4").End(xlToRight).Column
Set Rng = .Range(.Cells(1, 2), .Cells(5, C))
Lr = .Range("B" & Rows.Count).End(xlUp).Row
Arr = Range(.Cells(6, 2), .Cells(Lr, C)).Value
For i = 1 To UBound(Arr)
If Arr(i, 2) <> "" Then
Key = Arr(i, 2)
If Not dic.exists(Key) Then
dic.Add (Key), ""
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = Key
End If
End If
Next i
For Each Ws In Worksheets
If Ws.Name <> "TH" Then
ReDim Res(1 To UBound(Arr), 1 To C)
For i = 1 To UBound(Arr)
If Arr(i, 2) = Ws.Name Then
k = k + 1: Res(k, 1) = k
For j = 2 To 10
Res(k, j) = Arr(i, j)
Next j
End If
Next i
End If
If k Then
Rng.Copy Ws.Range("B1")
Ws.Range("B6").Resize(k, C).Value = Res
Ws.Range("D6").CurrentRegion.Borders.LineStyle = 1
Ws.Range("D6").CurrentRegion.EntireColumn.AutoFit
k = 0
End If
Next Ws
End With
Set dic = Nothing
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "Done"
End Sub