ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1345|回复: 7

求助VBA制作表格~急用

[复制链接]

TA的精华主题

TA的得分主题

发表于 2018-1-15 21:58 | 显示全部楼层 |阅读模式
将左侧表格按照受理网点所对应的业务名称和处理成功业务量做成红色模板表的格式

谢大神!!

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-1-15 22:00 | 显示全部楼层
下面是excel文件

excelhome--月报.rar

15.77 KB, 下载次数: 30

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-1-15 22:01 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2018-1-18 17:06 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

在sheet1后面新建一个表,选中sheet2右键查看代码,代码如下,注意:运行较慢
Sub ss()
Set a = Worksheets(1)
x = a.UsedRange.Rows.Count
Dim rng As Range, order As XlOrder, Header As XlYesNoGuess
Set rng = a.Range(a.Cells(1, 1), a.Cells(x, 3))
rng.Sort Key1:=a.Range(a.Cells(1, 1), a.Cells(1, 1)), Order1:=xlAscending, Header:=xlYes
m = 2
For i = 2 To x
If a.Cells(i, 1) <> a.Cells(i + 1, 1) And a.Cells(i, 1) <> "" Then
Cells(m, 1) = a.Cells(i, 1)
m = m + 1
End If
Next
Dim rg As Range
Set rg = a.Range(a.Cells(1, 1), a.Cells(x, 3))
rg.Sort Key1:=a.Range(a.Cells(1, 2), a.Cells(1, 2)), Order1:=xlAscending, Header:=xlYes
n = 2
For j = 2 To x
If a.Cells(j, 2) <> a.Cells(j + 1, 2) And a.Cells(j, 2) <> "" Then
Cells(1, n) = a.Cells(j, 2)
Cells(1, n + 1) = a.Cells(1, 3)
n = n + 2
End If
Next
xx = UsedRange.Rows.Count
y = UsedRange.Columns.Count
For e = 2 To xx
For f = 2 To y Step 2
For g = 2 To x
If Cells(e, 1) = a.Cells(g, 1) And Cells(1, f) = a.Cells(g, 2) Then
Cells(e, f) = a.Cells(g, 2)
Cells(e, f + 1) = a.Cells(g, 3)
End If
Next
Next
Next
End Sub

TA的精华主题

TA的得分主题

发表于 2018-1-18 17:12 | 显示全部楼层
在sheet1后面新建sheet2,选中sheet2右键查看代码,代码如下,注意运行较慢
  1. Sub ss()
  2. Set a = Worksheets(1)
  3. x = a.UsedRange.Rows.Count
  4. Dim rng As Range, order As XlOrder, Header As XlYesNoGuess
  5. Set rng = a.Range(a.Cells(1, 1), a.Cells(x, 3))
  6. rng.Sort Key1:=a.Range(a.Cells(1, 1), a.Cells(1, 1)), Order1:=xlAscending, Header:=xlYes
  7. m = 2
  8. For i = 2 To x
  9. If a.Cells(i, 1) <> a.Cells(i + 1, 1) And a.Cells(i, 1) <> "" Then
  10. Cells(m, 1) = a.Cells(i, 1)
  11. m = m + 1
  12. End If
  13. Next
  14. Dim rg As Range
  15. Set rg = a.Range(a.Cells(1, 1), a.Cells(x, 3))
  16. rg.Sort Key1:=a.Range(a.Cells(1, 2), a.Cells(1, 2)), Order1:=xlAscending, Header:=xlYes
  17. n = 2
  18. For j = 2 To x
  19. If a.Cells(j, 2) <> a.Cells(j + 1, 2) And a.Cells(j, 2) <> "" Then
  20. Cells(1, n) = a.Cells(j, 2)
  21. Cells(1, n + 1) = a.Cells(1, 3)
  22. n = n + 2
  23. End If
  24. Next
  25. xx = UsedRange.Rows.Count
  26. y = UsedRange.Columns.Count
  27. For e = 2 To xx
  28. For f = 2 To y Step 2
  29. For g = 2 To x
  30. If Cells(e, 1) = a.Cells(g, 1) And Cells(1, f) = a.Cells(g, 2) Then
  31. Cells(e, f) = a.Cells(g, 2)
  32. Cells(e, f + 1) = a.Cells(g, 3)
  33. End If
  34. Next
  35. Next
  36. Next
  37. End Sub

  38. [img]C:\Users\ASUS\Desktop\效果图.png[/img]
复制代码

TA的精华主题

TA的得分主题

发表于 2018-1-18 20:40 | 显示全部楼层

楼主,加速版来了,新建sheet2运行此代码,很快
  1. Sub 数组运行()        '4秒
  2. Set a = Worksheets(1)
  3. x = a.UsedRange.Rows.Count
  4. Dim rng As Range, order As XlOrder, Header As XlYesNoGuess
  5. Set rng = a.Range(a.Cells(1, 1), a.Cells(x, 3))
  6. rng.Sort Key1:=a.Range(a.Cells(1, 1), a.Cells(1, 1)), Order1:=xlAscending, Header:=xlYes
  7. m = 2
  8. Dim t()
  9. For i = 2 To x
  10. ReDim Preserve t(i)
  11. If a.Cells(i, 1) <> a.Cells(i + 1, 1) And a.Cells(i, 1) <> "" Then
  12. t(i) = a.Cells(i, 1)
  13. Cells(m, 1) = t(i)
  14. m = m + 1
  15. End If
  16. Next
  17. Dim rg As Range
  18. Set rg = a.Range(a.Cells(1, 1), a.Cells(x, 3))
  19. rg.Sort Key1:=a.Range(a.Cells(1, 2), a.Cells(1, 2)), Order1:=xlAscending, Header:=xlYes
  20. n = 2
  21. For j = 2 To x
  22. If a.Cells(j, 2) <> a.Cells(j + 1, 2) And a.Cells(j, 2) <> "" Then
  23. Cells(1, n) = a.Cells(j, 2)
  24. Cells(1, n + 1) = a.Cells(1, 3)
  25. n = n + 2
  26. End If
  27. Next
  28. xx = UsedRange.Rows.Count
  29. y = UsedRange.Columns.Count
  30. k = Range(Cells(2, 1), Cells(xx, 1))
  31. kk = Range(Cells(1, 2), Cells(1, y))
  32. kkk = a.Range(a.Cells(2, 1), a.Cells(x, 3))
  33. For e = 1 To xx - 1
  34. For f = 1 To y - 1 Step 2
  35. For g = 1 To x - 1
  36. If k(e, 1) = kkk(g, 1) And kk(1, f) = kkk(g, 2) Then
  37. Cells(e + 1, f + 1) = kkk(g, 2)
  38. Cells(e + 1, f + 2) = kkk(g, 3)
  39. End If
  40. Next
  41. Next
  42. Next
  43. End Sub
复制代码

TA的精华主题

TA的得分主题

发表于 2018-1-19 08:44 | 显示全部楼层

那啥,我好像看到了你的回复,但是我不知道在哪回答你,通用的话可能还不行,需要调整一些东西,但是如果是你这个格式的excel,只有一个工作表,同时只有三列数据,那是可以用的。如果用在其他文件上,可能需要调整一下

TA的精华主题

TA的得分主题

发表于 2018-1-19 10:56 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
对不起,前面仨有问题,漏了数据,现在是改版,应该不能跟格式不一样的通用,这个不用新建工作表,直接选中sheet1,右键查看代码,粘贴运行就行了
  1. Sub 数组运行()                                    '15秒
  2. Worksheets.Add after:=Worksheets("sheet1")
  3. ActiveSheet.Name = "汇总"
  4. Set b = Worksheets("汇总")
  5. Set a = Worksheets(1)
  6. x = a.UsedRange.Rows.Count
  7. Dim rng As Range, order As XlOrder, Header As XlYesNoGuess
  8. Set rng = a.Range(a.Cells(1, 1), a.Cells(x, 3))
  9. rng.Sort Key1:=a.Range(a.Cells(1, 1), a.Cells(1, 1)), Order1:=xlAscending, Header:=xlYes
  10. m = 2
  11. Dim t()
  12. For i = 2 To x
  13. ReDim Preserve t(i)
  14. If a.Cells(i, 1) <> a.Cells(i + 1, 1) And a.Cells(i, 1) <> "" Then
  15. t(i) = a.Cells(i, 1)
  16. b.Cells(m, 1) = t(i)
  17. m = m + 1
  18. End If
  19. Next
  20. Dim rg As Range
  21. Set rg = a.Range(a.Cells(1, 1), a.Cells(x, 3))
  22. rg.Sort Key1:=a.Range(a.Cells(1, 2), a.Cells(1, 2)), Order1:=xlAscending, Header:=xlYes
  23. n = 2
  24. For j = 2 To x
  25. If a.Cells(j, 2) <> a.Cells(j + 1, 2) And a.Cells(j, 2) <> "" Then
  26. b.Cells(1, n) = a.Cells(j, 2)
  27. b.Cells(1, n + 1) = a.Cells(1, 3)
  28. n = n + 2
  29. End If
  30. Next
  31. xx = UsedRange.Rows.Count
  32. y = UsedRange.Columns.Count
  33. k = b.Range(b.Cells(2, 1), b.Cells(xx, 1))
  34. kk = b.Range(b.Cells(1, 2), b.Cells(1, y))
  35. kkk = a.Range(a.Cells(2, 1), a.Cells(x, 3))
  36. For e = 1 To xx - 1
  37. For f = 1 To y - 1 Step 2
  38. For g = 1 To x - 1
  39. If k(e, 1) = kkk(g, 1) And kk(1, f) = kkk(g, 2) Then
  40. b.Cells(e + 1, f + 1) = kkk(g, 2)
  41. b.Cells(e + 1, f + 2) = kkk(g, 3) + b.Cells(e + 1, f + 2)
  42. End If
  43. Next
  44. Next
  45. Next
  46. b.Cells(1, 1) = "受理网点"
  47. End Sub

复制代码
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-26 11:37 , Processed in 0.048586 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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