Excel精英培训网

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

[已解决]多条件汇总多项数据

[复制链接]
发表于 2016-6-22 16:44 | 显示全部楼层 |阅读模式
本帖最后由 hxgfkfb 于 2016-6-23 08:32 编辑

Data.rar (7.88 KB, 下载次数: 23)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2016-6-22 17:03 | 显示全部楼层
回复

使用道具 举报

发表于 2016-6-22 17:06 | 显示全部楼层    本楼为最佳答案   
如果一定要通过VBA,代码如下,但如果只做数据统计用,针对你这个我建议还是用数据透视表!
  1. Sub xx()
  2.     Dim n&, arr, d, brr, i%
  3.     Set d = CreateObject("scripting.dictionary")
  4.     With Sheet1
  5.         n = .Cells(.Rows.Count, 1).End(xlUp).Row
  6.         arr = .Range("B2:H" & n)
  7.         For i = 1 To n - 1
  8.             If d.Exists(arr(i, 1) & "|" & arr(i, 3)) Then
  9.                 d(arr(i, 1) & "|" & arr(i, 3)) = Split(d(arr(i, 1) & "|" & arr(i, 3)), "|")(0) + arr(i, 6) & "|" & Split(d(arr(i, 1) & "|" & arr(i, 3)), "|")(1) + arr(i, 7)
  10.             Else
  11.                 d.Add arr(i, 1) & "|" & arr(i, 3), arr(i, 6) & "|" & arr(i, 7)
  12.             End If
  13.         Next
  14.     End With
  15.     x = 1
  16.     With Sheet2
  17.         For Each k In d.keys
  18.             x = x + 1
  19.             .Cells(x, 1) = Split(k, "|")(0)
  20.             .Cells(x, 2) = Split(k, "|")(1)
  21.             .Cells(x, 3) = Split(d(k), "|")(0)
  22.             .Cells(x, 4) = Split(d(k), "|")(1)
  23.         Next
  24.     End With
  25. End Sub
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 04:37 , Processed in 0.435398 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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