|
- Sub test()
- Dim r%, i%
- Dim arr, brr, fs(1 To 2)
- 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
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- bt = .Range("a1").Resize(1, c)
- arr = .Range("a2").Resize(r - 1, c)
- End With
- For j = 1 To UBound(bt, 2)
- If InStr("语文数学英语总分", bt(1, j)) <> 0 Then
- fs(1) = Application.Large(Application.Index(arr, 0, j), 200)
- fs(2) = Application.Small(Application.Index(arr, 0, j), 200)
- If bt(1, j) = "总分" Then
- ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
- ReDim crr(1 To UBound(arr), 1 To UBound(arr, 2))
- m = 0
- n = 0
- For i = 1 To UBound(arr)
- If arr(i, j) >= fs(1) Then
- m = m + 1
- For k = 1 To UBound(arr, 2)
- brr(m, k) = arr(i, k)
- Next
- End If
- If arr(i, j) <= fs(2) Then
- n = n + 1
- For k = 1 To UBound(arr, 2)
- crr(n, k) = arr(i, k)
- Next
- End If
- Next
- Else
- ReDim brr(1 To UBound(arr), 1 To 8)
- ReDim crr(1 To UBound(arr), 1 To 8)
- m = 0
- n = 0
- For i = 1 To UBound(arr)
- If arr(i, j) >= fs(1) Then
- m = m + 1
- For k = 1 To 6
- brr(m, k) = arr(i, k)
- Next
- brr(m, 7) = arr(i, j)
- End If
- If arr(i, j) <= fs(2) Then
- n = n + 1
- For k = 1 To 6
- crr(n, k) = arr(i, k)
- Next
- crr(n, 7) = arr(i, j)
- End If
- Next
- End If
- If Not d.exists(1) Then
- Set d(1) = CreateObject("scripting.dictionary")
- End If
- If Not d.exists(2) Then
- Set d(2) = CreateObject("scripting.dictionary")
- End If
- d(1)(bt(1, j)) = brr
- d(2)(bt(1, j)) = crr
- End If
- Next
- For Each aa In d.keys
- For Each bb In d(aa).keys
- If bb = "总分" Then
- wjm = bb & IIf(aa = 1, "前", "倒数") & "200名学生"
- Else
- wjm = bb & "单科" & IIf(aa = 1, "前", "倒数") & "200名学生"
- End If
- brr = d(aa)(bb)
- On Error Resume Next
- Set ws = Worksheets(wjm)
- If Err Then
- Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
- ws.Name = wjm
- End If
- On Error GoTo 0
- With Worksheets(wjm)
- .UsedRange.Offset(1, 0).Clear
- .Range("a2").Resize(UBound(brr), UBound(brr, 2)) = brr
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- If r > 1 Then
- .Range("a1").Resize(r, c).Sort key1:=.Cells(2, IIf(bb = "总分", 10, 7)), order1:=IIf(aa = 1, xlDescending, xlAscending), Header:=xlYes
- End If
-
- End With
- Next
- Next
- End Sub
复制代码 |
|