本帖最后由 liulang0808 于 2024-11-19 13:25 编辑
Sub 按钮1_Click()
Set d = CreateObject("scripting.dictionary")
arr = Sheets("原始表").UsedRange
For j = 2 To UBound(arr)
If Not d.exists(arr(j, 1)) Then
Set d(arr(j, 1)) = CreateObject("scripting.dictionary")
End If
If arr(j, 8) <> "单科状元" Then
d(arr(j, 1))(arr(j, 8)) = d(arr(j, 1))(arr(j, 8)) + 1
Else
d(arr(j, 1))(arr(j, 9)) = d(arr(j, 1))(arr(j, 9)) + 1
End If
Next j
Sheets("目标表1").UsedRange.Offset(2, 1).ClearContents
arr = Sheets("目标表1").UsedRange
For j = 4 To UBound(arr)
For i = 3 To 4
arr(j, i) = Val(d(arr(j, 1))(arr(1, i)))
arr(3, i) = arr(j, i) + arr(3, i)
arr(3, 2) = arr(j, i) + arr(3, 2)
arr(j, 2) = arr(j, i) + arr(j, 2)
Next i
For i = 6 To 10
arr(j, i) = Val(d(arr(j, 1))(arr(2, i)))
arr(3, i) = arr(j, i) + arr(3, i)
arr(3, 2) = arr(j, i) + arr(3, 2)
arr(3, 5) = arr(j, i) + arr(3, 5)
arr(j, 5) = arr(j, i) + arr(j, 5)
arr(j, 2) = arr(j, i) + arr(j, 2)
Next i
Next j
Sheets("目标表1").UsedRange = arr
Sheets("目标表2").UsedRange.Offset(1, 1).ClearContents
arr = Sheets("目标表2").UsedRange
brr = Array("语文", 0, "数学", 0, "英语", 0, "物理", 0, "政治", 0)
For j = 3 To UBound(arr)
arr(j, 3) = Val(d(arr(j, 1))(arr(1, 3)))
arr(j, 4) = Val(d(arr(j, 1))(arr(1, 4)))
sm = 0
str1 = ""
For i = 0 To UBound(brr) Step 2
k = brr(i)
brr(i + 1) = brr(i + 1) + Val(d(arr(j, 1))(k))
sm = sm + Val(d(arr(j, 1))(k))
str1 = str1 & ";" & k & Val(d(arr(j, 1))(k)) & "人"
Next
arr(j, 2) = sm + arr(j, 3) + arr(j, 4)
arr(2, 2) = arr(2, 2) + arr(j, 2)
arr(2, 3) = arr(2, 3) + arr(j, 3)
arr(2, 4) = arr(2, 4) + arr(j, 4)
arr(j, 5) = sm & "人,其中," & Mid(str1, 2)
Next j
str1 = ""
sm = 0
For i = 0 To UBound(brr) Step 2
k = brr(i)
sm = sm + brr(i + 1)
str1 = str1 & ";" & k & brr(i + 1) & "人"
Next
arr(2, 5) = sm & "人,其中," & Mid(str1, 2)
Sheets("目标表2").UsedRange = arr
End Sub
|