tplk 发表于 2013-2-14 16:03
搞定了,谢谢老师的帮忙,真心感谢 - Private Sub Worksheet_Change(ByVal Target As Range)
- If Target.Address(0, 0) <> "B3" And Target.Address(0, 0) <> "G1" Then Exit Sub
- If dicValidation Is Nothing Then Call Macro1
- If Target.Address(0, 0) = "G1" Then
- With [b3].Validation
- .Delete
- If dicValidation.Exists(Target.Value) Then .Add 3, 1, 1, Join(dicValidation(Target.Value).keys, ",")
- End With
- [b3] = ""
- Exit Sub
- End If
- Range("A5:O38").ClearContents
- If [b3] = "" Then Exit Sub
- Dim c As Range, c2 As Range, arr, i&, 校$, 班$, brr(100, 1 To 2), n&, rng As Range
- Dim crr(1 To 34, 1 To 15), hj As Double, j&, m&, mc&
- 校 = Range("g1").Value
- 班 = Range("b3").Value
- With Sheets("学生成绩源")
- Set c = .[a:a].Find(校, , , xlWhole)
- If c Is Nothing Then
- MsgBox 校 & "没有查到"
- Exit Sub
- End If
- Set rng = c.Offset(, 2).Resize(.[a:a].Find(校, , , xlWhole, , xlPrevious).Row - c.Row + 1)
- Set c2 = rng.Find(班, rng.Cells(rng.Rows.Count), , xlWhole)
- If c2 Is Nothing Then
- MsgBox 班 & "没有查到"
- Exit Sub
- End If
- arr = c2.Resize(rng.Find(班, , , xlWhole, , xlPrevious).Row - c2.Row + 1, 5)
- End With
- n = 1
- brr(1, 2) = 0
- For i = 1 To UBound(arr)
- hj = arr(i, 3) + arr(i, 4) + arr(i, 5)
- For j = 1 To n
- If hj >= brr(j, 2) Then
- For m = n To j Step -1
- brr(m + 1, 1) = brr(m, 1)
- brr(m + 1, 2) = brr(m, 2)
- Next
- brr(j, 1) = i
- brr(j, 2) = hj
- Exit For
- End If
- Next
- n = n + 1
- Next
- For i = 1 To n - 1
- If i > 34 Then
- x = i - 34
- y = 8
- Else
- x = i
- y = 0
- End If
- If brr(i, 2) <> brr(i - 1, 2) Then mc = i
- crr(x, 1 + y) = mc
- For j = 2 To 5
- crr(x, j + y) = arr(brr(i, 1), j)
- Next
- crr(x, 6 + y) = brr(i, 2)
- Next
- Range("a5:o38") = crr
- End Sub
复制代码 |