Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3034|回复: 3

[已解决]数据统计修改

[复制链接]
发表于 2015-12-21 18:47 | 显示全部楼层 |阅读模式
本帖最后由 cyj153 于 2015-12-22 18:06 编辑

数据统计2.zip (21.39 KB, 下载次数: 10)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2015-12-21 19:25 | 显示全部楼层
附件

数据统计2.zip

22.27 KB, 下载次数: 7

回复

使用道具 举报

发表于 2015-12-21 20:42 | 显示全部楼层
  1. Sub test()
  2.     Dim x As Integer, arr, m As Integer, brr, yx, lh, jg, bjg, wcs, k
  3.     Set d = CreateObject("scripting.dictionary")
  4.     m = Sheets("高三年级").Range("e65536").End(3).Row
  5.     arr = Sheets("高三年级").Range("e1:z" & m)
  6.     For x = 2 To UBound(arr)
  7.         If arr(x, 1) <> "" Then
  8.             d(arr(x, 1)) = 1
  9.         End If
  10.     Next
  11.     brr = d.keys
  12.     With Sheets("表3")
  13.         .Range("a6").Resize(UBound(brr) + 1, 1) = Application.Transpose(brr)
  14.         crr = .Range("a6:q" & Sheets("表3").Range("a65536").End(3).Row)
  15.         yx = 0
  16.         lh = 0
  17.         jg = 0
  18.         bjg = 0
  19.         wcs = 0
  20.         k = 0
  21.         For x = 1 To UBound(crr)
  22.             For y = 1 To UBound(arr)
  23.                 If crr(x, 1) = arr(y, 1) Then
  24.                     crr(x, 2) = arr(y, 2)
  25.                     crr(x, 3) = arr(y, 3)
  26.                     k = k + 1
  27.                     If arr(y, 22) = "优秀" Then yx = yx + 1
  28.                     If arr(y, 22) = "良好" Then lh = lh + 1
  29.                     If arr(y, 22) = "及格" Then jg = jg + 1
  30.                     If arr(y, 22) = "不及格" Then bjg = bjg + 1
  31.                     If arr(y, 22) = "未测试" Then wcs = wcs + 1
  32.                 End If
  33.             Next
  34.             .Cells(x + 5, 1) = crr(x, 1)
  35.             .Cells(x + 5, 2) = crr(x, 2)
  36.             .Cells(x + 5, 3) = crr(x, 3)
  37.             .Cells(x + 5, 4) = k

  38.             .Cells(x + 5, 5) = yx
  39.             .Cells(x + 5, 6) = yx / k
  40.             .Cells(x + 5, 6).NumberFormatLocal = "0.00%"

  41.             .Cells(x + 5, 7) = lh
  42.             .Cells(x + 5, 8) = lh / k
  43.             .Cells(x + 5, 8).NumberFormatLocal = "0.00%"

  44.             .Cells(x + 5, 9) = jg
  45.             .Cells(x + 5, 10) = jg / k
  46.             .Cells(x + 5, 10).NumberFormatLocal = "0.00%"

  47.             .Cells(x + 5, 11) = bjg
  48.             .Cells(x + 5, 12) = bjg / k
  49.             .Cells(x + 5, 12).NumberFormatLocal = "0.00%"

  50.             .Cells(x + 5, 13) = bjg
  51.             .Cells(x + 5, 14) = bjg / k
  52.             .Cells(x + 5, 14).NumberFormatLocal = "0.00%"

  53.             .Cells(x + 5, 15) = yx + lh + jg
  54.             .Cells(x + 5, 16) = (yx + lh + jg) / k
  55.             .Cells(x + 5, 16).NumberFormatLocal = "0.00%"

  56.             yx = 0
  57.             lh = 0
  58.             jg = 0
  59.             bjg = 0
  60.             wcs = 0
  61.             k = 0
  62.         Next
  63.     End With

  64. End Sub

复制代码
请测试,看看是不是这样?

数据统计2.rar

20.94 KB, 下载次数: 5

回复

使用道具 举报

发表于 2015-12-22 13:33 | 显示全部楼层    本楼为最佳答案   
  1. Sub 统计2()
  2.    arr = Sheets(1).Range("a1").CurrentRegion
  3.    ReDim brr(1 To UBound(arr), 1 To 16)
  4.    Set d = CreateObject("scripting.dictionary")
  5.    For i = 3 To UBound(arr)
  6.       x = arr(i, 5): y = arr(i, 26) '年级、等级
  7.       If Len(x) Then
  8.          If Not d.exists(x) Then
  9.             n = n + 1
  10.             d(x) = n
  11.             brr(n, 1) = arr(i, 5)
  12.             brr(n, 2) = arr(i, 6)
  13.             brr(n, 3) = arr(i, 7)
  14.          End If
  15.          brr(d(x), 4) = brr(d(x), 4) + 1
  16.          If Len(y) = 0 Then y = "未测试"
  17.          x1 = x & y
  18.          d(x1) = d(x1) + 1
  19.          If InStr("优秀良好及格", y) > 0 Then
  20.             x1 = x & "合格总数"
  21.             d(x1) = d(x1) + 1
  22.         End If
  23.       End If
  24.    Next
  25.    With ActiveSheet
  26.         .[a6:p300].ClearContents
  27.         .[a6].Resize(n, 4) = brr
  28.         crr = .[a4].Resize(n + 2, 16)
  29.             For j = 5 To 15 Step 2
  30.                 x = crr(1, j)
  31.                 For i = 3 To UBound(crr)
  32.                     y = crr(i, 1) & x
  33.                     crr(i, j) = d(y)
  34.                     If crr(i, j) * crr(i, 4) > 0 Then crr(i, j + 1) = crr(i, j) / crr(i, 4)
  35.                 Next
  36.             Next
  37.         .[a4].Resize(n + 2, 16) = crr
  38.     End With
  39. End Sub
复制代码

数据统计2.rar

21.84 KB, 下载次数: 11

评分

参与人数 1 +1 收起 理由
lidayu + 1 赞一个

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-24 02:10 , Processed in 0.269102 second(s), 15 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表