Sub Export()
Dim dic As Object, rngSrc As Range, wkbNew As Workbook
Dim aIDs, n As Long
Dim sFolder As String, FileName As String, SheetName As String
sFolder = ThisWorkbook.Path & "\Export_"
Set rngSrc = ThisWorkbook.Worksheets("Sheet8").Range("A1:AL9000")
aIDs = rngSrc.Offset(1).Columns("A:B").Value
Set dic = CreateObject("Scripting.Dictionary")
Application.ScreenUpdating = False
rngSrc.Range("IV1").Value = rngSrc.Range("A1").Value
For n = 1 To UBound(aIDs, 1)
If Len(aIDs(n, 1)) * Len(aIDs(n, 2)) Then
SheetName = aIDs(n, 1): FileName = aIDs(n, 1)
If Not dic.Exists(SheetName) Then
dic.Add SheetName, Empty
Set wkbNew = Workbooks.Add(1)
wkbNew.Sheets(1).Name = SheetName
rngSrc.Range("IV2").Value = "'=" & SheetName
rngSrc.AdvancedFilter 2, rngSrc.Range("IV1:IV2"), wkbNew.Sheets(1).Range("A1")
wkbNew.SaveAs sFolder & FileName, xlOpenXMLWorkbook
wkbNew.Close False
End If
End If
Next
Application.ScreenUpdating = True
rngSrc.Range("IV1:IV2").ClearContents
If dic.Count Then MsgBox "Ða luu " & dic.Count & " workbooks", , "THÔNG BÁO"
End Sub