|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 mjzxlmg 于 2013-12-15 23:40 编辑
dyzx 发表于 2013-12-15 17:18
能够增加几个项目部那就更好了。如附件 - Sub test()
- Dim title(), score_1(), score_2(), i&, j&, data_in, data_out, dic As Object, m%, n%, s%, k%, ii%, jj%, iii&, jjj&
- Set dic = CreateObject("scripting.dictionary")
- title = Array("学校", "实考人数", "总分", "平均分", "最高分", "最低分")
- score_1 = Array(150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0.1)
- score_2 = Array(140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0.1, 0)
- Dim tt
- tt = Timer
- Application.ScreenUpdating = False
- data_in = Sheet2.[a1].CurrentRegion.Value
- ReDim data_out(UBound(data_in), UBound(score_1) + 2 + UBound(title))
- m = 1
- n = 2
- For j = 3 To UBound(data_in, 2)
- data_out(m - 1, 0) = data_in(1, j)
- For jjj = LBound(title) To UBound(title)
- data_out(m, jjj) = title(jjj)
- Next
- For jjj = LBound(score_1) To UBound(score_1)
- data_out(m, jjj + 1 + UBound(title)) = score_2(jjj) & "~" & score_1(jjj)
- Next
- For i = 2 To UBound(data_in)
- If data_in(i, j) Then '0分不计算实考人数,改为:If Len(data_in(i, j)) Then ,0分计算实考人数,
- s = dic(data_in(i, 1))
- If s = Empty Then
- m = m + 1
- dic(data_in(i, 1)) = m
- s = m
- data_out(s, 0) = data_in(i, 1)
- data_out(s, 4) = data_in(i, j)
- data_out(s, 5) = data_in(i, j)
- End If
- data_out(s, 1) = data_out(s, 1) + 1
- data_out(s, 2) = data_out(s, 2) + data_in(i, j)
- data_out(s, 3) = data_out(s, 2) / data_out(s, 1)
- If data_in(i, j) > data_out(s, 4) Then data_out(s, 4) = data_in(i, j)
- If data_in(i, j) < data_out(s, 5) Then data_out(s, 5) = data_in(i, j)
- For k = LBound(score_1) To UBound(score_1)
- If data_in(i, j) >= score_2(k) And data_in(i, j) < score_1(k) Then data_out(s, UBound(title) + 1 + k) = data_out(s, UBound(title) + 1 + k) + 1
- Next
- End If
- Next
- For jj = 1 To UBound(data_out, 2)
- For ii = n To m
- If jj <> 3 And jj <> 4 And jj <> 5 Then data_out(m + 1, jj) = data_out(m + 1, jj) + data_out(ii, jj)
- If jj = 4 Then
- If data_out(m + 1, 4) = "" Then data_out(m + 1, 4) = data_out(ii, 4)
- If data_out(ii, 4) > data_out(m + 1, 4) Then data_out(m + 1, 4) = data_out(ii, 4)
- End If
- If jj = 5 Then
- If data_out(m + 1, 5) = "" Then data_out(m + 1, 5) = data_out(ii, 5)
- If data_out(ii, 5) < data_out(m + 1, 5) Then data_out(m + 1, 5) = data_out(ii, 5)
- End If
- Next
- Next
- data_out(m + 1, 0) = "总计"
- data_out(m + 1, 3) = data_out(m + 1, 2) / data_out(m + 1, 1)
- dic.RemoveAll
- m = m + 4
- n = m + 1
- Next
- With ActiveSheet
- .UsedRange.ClearContents
- .[a2].Resize(m + 1, UBound(data_out, 2)).Value = data_out
- End With
- Application.ScreenUpdating = True
- MsgBox Timer - tt
- End Sub
复制代码 |
|