Public Sub GPE_002()
Dim Dic As Object, Tmp As String, Arr, Pth, ShMain As Worksheet, sArr, dArr, N As Long
Dim I As Long, K As Long, WbMain As Workbook, Sh As Worksheet, Col As Long, J As Long
sArr = Array("stt", "sobhxh", "sokcb", "madt", "hoten", "ngaysinh", "gioitinh", "noikhai", "diachi", "diachihk", "tamtru", _
"noicapso", "mapb", "socmnd", "ngaycmnd", "noicap", "ma_tinh", "ma_bv", "dantoc", "quoctich", "hsl", "ml", "pa", "tuthang", _
"denthang", "tyle", "congviec", "macv")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.SheetsInNewWorkbook = 1
Set WbMain = ThisWorkbook
Set ShMain = WbMain.Sheets("bc04261355")
Arr = ShMain.Range("A1").CurrentRegion
ReDim dArr(1 To UBound(Arr), 1 To UBound(sArr) + 1)
Pth = ActiveWorkbook.Path
Set Dic = CreateObject("Scripting.Dictionary")
With Dic
For J = 2 To UBound(Arr)
Tmp = Arr(J, 2)
If Not .Exists(Tmp) Then
N = N + 1
.Add Tmp, N
With Workbooks.Add
Set Sh = .Sheets(1)
Sh.Name = Tmp
For Col = 0 To UBound(sArr)
dArr(1, Col + 1) = sArr(Col)
Next Col
K = 1
For I = 2 To UBound(Arr)
If Arr(I, 2) = Tmp Then
K = K + 1
dArr(K, 1) = K - 1
dArr(K, 2) = Arr(I, 3)
dArr(K, 3) = Arr(I, 8)
dArr(K, 5) = Arr(I, 4) & " " & Arr(I, 5)
dArr(K, 6) = Arr(I, 6)
If Arr(I, 7) = 0 Then dArr(K, 7) = "x"
dArr(K, 9) = Arr(I, 12)
dArr(K, 13) = Arr(I, 15)
dArr(K, 14) = Arr(I, 9)
dArr(K, 15) = Arr(I, 10)
dArr(K, 16) = Arr(I, 11)
dArr(K, 17) = Arr(I, 13)
dArr(K, 18) = Arr(I, 14)
dArr(K, 21) = Arr(I, 20)
dArr(K, 22) = Arr(I, 17)
dArr(K, 23) = Arr(I, 27)
dArr(K, 28) = Arr(I, 29)
End If
Next I
Sheets(Tmp).Range("A1").Offset(, 1).Resize(K).NumberFormat = "@"
Sheets(Tmp).Range("A1").Offset(, 13).Resize(K).NumberFormat = "@"
Sheets(Tmp).Range("A1").Offset(, 17).Resize(K).NumberFormat = "@"
Sheets(Tmp).Range("A1").Resize(K, UBound(sArr) + 1).Value = dArr
Sheets(Tmp).Range("A1").Resize(K, UBound(sArr) + 1).Font.Name = ".VnTime"
.Close True, Pth & "\" & Tmp & ".xlsx"
End With
End If
Next J
End With
Set Dic = Nothing
Application.SheetsInNewWorkbook = 3
MsgBox "Da Tach Xong!"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub