|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("总成绩表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- .Range("l2:n" & r).ClearContents
- arr = .Range("a1:n" & r)
- For i = 2 To UBound(arr)
- For j = 4 To 11
- arr(i, 12) = arr(i, 12) + arr(i, j)
- Next
- d(arr(i, 12)) = d(arr(i, 12)) + 1
- If Not d1.exists(arr(i, 1)) Then
- Set d1(arr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- d1(arr(i, 1))(arr(i, 12)) = d1(arr(i, 1))(arr(i, 12)) + 1
- Next
- nn = 1
- kk = d.keys
- For k = 0 To UBound(kk)
- mm = Application.Large(kk, k + 1)
- ss = d(mm)
- d(mm) = nn
- nn = nn + ss
- Next
- For Each aa In d1.keys
- nn = 1
- kk = d1(aa).keys
- For k = 0 To UBound(kk)
- mm = Application.Large(kk, k + 1)
- ss = d1(aa)(mm)
- d1(aa)(mm) = nn
- nn = nn + ss
- Next
- Next
- For i = 2 To UBound(arr)
- arr(i, 13) = d(arr(i, 12))
- arr(i, 14) = d1(arr(i, 1))(arr(i, 12))
- Next
- .Range("a1").Resize(UBound(arr), UBound(arr, 2)) = arr
- d.RemoveAll
- d1.RemoveAll
- For i = 2 To UBound(arr)
- bj = CStr(arr(i, 1))
- If Not d.exists(bj) Then
- Set d(bj) = .Range("a1:n1")
- End If
- Set d(bj) = Union(d(bj), .Cells(i, 1).Resize(1, 14))
- Next
- End With
- For Each aa In d.keys
- On Error Resume Next
- Set ws = Worksheets(aa & "班")
- If Err Then
- Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
- ws.Name = aa & "班"
- End If
- On Error GoTo 0
- With Worksheets(aa & "班")
- .Cells.Clear
- d(aa).Copy .Range("a1")
- End With
- Next
- Application.ScreenUpdating = True
- MsgBox "数据拆分完毕!"
- End Sub
复制代码 |
评分
-
5
查看全部评分
-
|