|
Sub test()
Dim arr
Dim wb As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set d = CreateObject("scripting.dictionary")
With Worksheets("高一")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
c = .Cells(1, .Columns.Count).End(xlToLeft).Column
arr = .Range("a1:ah" & r)
Set rng = .[a1].Resize(1, c)
For i = 2 To UBound(arr)
If Not d.Exists(arr(i, 2)) Then
Set d(arr(i, 2)) = .Cells(i, 1).Resize(1, c)
Else
Set d(arr(i, 2)) = Union(d(arr(i, 2)), .Cells(i, 1).Resize(1, c))
End If
Next
End With
For Each aa In d.Keys
Set wb = Workbooks.Add
With wb
With .Worksheets(1)
.Name = "高一" & aa & "班"
rng.Copy .[a1]
d(aa).Copy .[a2]
End With
.SaveAs Filename:=ThisWorkbook.Path & "\" & "高一" & aa & "班"
.Close False
End With
Next
Application.ScreenUpdating = True
MsgBox "数据拆分完毕!"
End Sub
|
|