|
Sub qs() '2024/7/1
Application.ScreenUpdating = False: Application.DisplayAlerts = False
Dim wb As Workbook, xwb As Workbook, sht As Worksheet, dic As Object, i, k, arr
Set wb = ThisWorkbook: Set sht = wb.Sheets("sheet1")
Set dic = CreateObject("scripting.dictionary")
arr = sht.Range("a1").CurrentRegion.Value
For i = 2 To UBound(arr)
If Not dic.exists(arr(i, 10)) Then
dic(arr(i, 10)) = ""
End If
Next
With sht.Range("a1").CurrentRegion
For Each k In dic.keys
.AutoFilter
.AutoFilter Field:=10, Criteria1:=k
Set xwb = Workbooks.Add
.Copy xwb.Sheets(1).Range("a1")
xwb.SaveAs ThisWorkbook.Path & "\" & k & ".xlsx"
xwb.Close
Next
.AutoFilter
End With
Application.ScreenUpdating = True: Application.DisplayAlerts = True
Set wb = Nothing: Set xwb = Nothing: Set dic = Nothing: Set sht = Nothing
MsgBox "拆分完成"
End Sub
|
|