|
Option Explicit
Sub TEST1()
Dim ar, br, cr, i&, j&, dic As Object, vKey, shp As Shape
Dim Rng As Range, strPath$, wks As Worksheet, strFileName$
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set dic = CreateObject("Scripting.Dictionary")
Set Rng = [A1:O20]
ar = Rng.Value
For i = 6 To UBound(ar)
dic(ar(i, 5)) = dic(ar(i, 5)) & " " & i
Next i
strPath = ThisWorkbook.Path & "\拆分后各班情况\"
If Dir(strPath, vbDirectory) = "" Then MkDir strPath
For Each vKey In dic.keys
cr = Split(dic(vKey))
ReDim br(1 To UBound(cr), 1 To 5)
For i = 1 To UBound(cr)
For j = 1 To UBound(br, 2)
br(i, j) = ar(cr(i), j)
Next j
Next i
With Workbooks.Add
strFileName = strPath & vKey
With Worksheets(1)
Rng.Copy .[A1]
.Name = vKey
.[A3].CurrentRegion.Offset(3).Clear
.[A6].Resize(UBound(br), UBound(br, 2)) = br
For Each shp In .Shapes
shp.Delete
Next
End With
For Each wks In .Worksheets
If wks.Name Like "*Sheet*" Then wks.Delete
Next
.SaveAs strFileName: .Close
End With
Next
Set dic = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
3
查看全部评分
-
|