|
- Option Explicit
- Sub l()
- Dim arr As Variant, brr() As Variant
- Dim d As Object
- Dim i As Integer
- Dim j As Integer, k As Integer, n As Integer
- Dim a As Variant, b As Variant, c As Variant
- Dim rng As Range, bb As Integer
- Dim tmp As String
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set rng = Sheet3.Range("a1:q1")
- arr = Sheet3.Range("a1").CurrentRegion
- Set d = CreateObject("scripting.dictionary")
- bb = Application.InputBox("请选择:" & vbCrLf & "1、按学校拆分;" & vbCrLf & "2、按学校、年级、班级拆分", "选择拆分类型")
- For i = 2 To UBound(arr)
- If bb = 1 Then tmp = arr(i, 7) Else tmp = arr(i, 7) & arr(i, 8) & "年级" & arr(i, 9) & "班"
- d(tmp) = d(tmp) & "," & i
- Next
- a = d.keys
- b = d.items
- For i = 0 To UBound(a)
- ReDim brr(1 To 10000, 1 To 17)
- c = Split(Mid(b(i), 2), ",")
- n = 0
- For j = 0 To UBound(c)
- n = n + 1
- For k = 1 To 17
- brr(n, k) = arr(c(j), k)
- Next
- Next
- Workbooks.Add
- With ActiveSheet
- rng.Copy .Range("a1")
- .Range("a1").CurrentRegion.Offset(1).Clear
- .Range("a2").Resize(n, 17).Value = brr
- .Range("e:e").NumberFormatLocal = "yyyy-mm-dd"
- .Range("p:p").NumberFormatLocal = "000000"
- End With
- ActiveWorkbook.SaveAs ThisWorkbook.Path & "" & a(i) & ".xls"
- ActiveWorkbook.Close True
- Next
- Set d = Nothing
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- End Sub
复制代码 |
|