|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 按班级拆分()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim ar As Variant, cr As Variant
Dim i As Long, r As Long, rs As Long
Dim br(), brr()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
lj = ThisWorkbook.Path & "\"
If Dir(lj & "拆分的工作簿", vbDirectory) = "" Then MkDir lj & "拆分的工作簿"
Set sht = ThisWorkbook.Sheets(1)
With Sheets("sheet1")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(2, Columns.Count).End(xlToLeft).Column
If r < 3 Or y < 4 Then MsgBox "成绩表工作表为空,请先导入数据!": End
ar = .Range(.Cells(1, 1), .Cells(r, y))
mc = .[a1]
For i = 3 To UBound(ar)
If ar(i, 1) <> "" Then
If Not d.exists(ar(i, 1)) Then
Set d(ar(i, 1)) = .Rows(i)
Else
Set d(ar(i, 1)) = Union(d(ar(i, 1)), .Rows(i))
End If
End If
Next i
End With
x = d.keys
For i = 0 To UBound(x)
sht.Copy
Set wb = ActiveWorkbook
With wb.Worksheets(1)
.UsedRange.Offset(2).Borders.LineStyle = 0
.UsedRange.Offset(2) = Empty
d.items()(i).Copy .[a3]
.Name = x(i) & "班"
For Each shp In .Shapes
shp.Delete
Next shp
End With
wb.SaveAs fileName:=ThisWorkbook.Path & "\拆分的工作簿\" & mc & x(i) & "班成绩统计表.xlsx"
wb.Close
Next i
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "拆分完毕!", 64, "提醒!"
End Sub
|
|