Excel精英培训网

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

[已解决]请VBA高手,帮帮我,怎样才能达成这样的效果。

[复制链接]
发表于 2012-8-23 15:40 | 显示全部楼层 |阅读模式
请VBA的高手们,帮我达成这种效果。

如图:


822.jpg
ch]246203[/attach]
自动复制粘贴.rar (7.29 KB, 下载次数: 24)
发表于 2012-8-23 16:10 | 显示全部楼层    本楼为最佳答案   
  1. Sub test()
  2. Dim d As Object
  3. Dim x&
  4. Dim arr, brr
  5. Set d = CreateObject("Scripting.Dictionary")

  6. For x = 5 To Cells(Rows.Count, "k").End(3).Row
  7.     d(Cells(x, "k").Value) = Cells(x, "r").Value
  8. Next
  9. For x = 5 To Cells(Rows.Count, "ah").End(3).Row
  10.     d(Cells(x, "ah").Value) = Cells(x, "ao").Value
  11. Next

  12. arr = d.keys
  13. brr = d.items

  14. For x = 0 To UBound(arr)
  15.     Cells(5 + x, "k") = arr(x)
  16.     Cells(5 + x, "r") = brr(x)
  17. Next
  18. Set d = Nothing
  19. End Sub
复制代码
回复

使用道具 举报

 楼主| 发表于 2012-8-23 18:16 | 显示全部楼层
zm0115 发表于 2012-8-23 16:10

老师·················
180426.jpg
回复

使用道具 举报

发表于 2012-8-23 22:20 | 显示全部楼层
excel010 发表于 2012-8-23 18:16
老师·················
  1. Sub test()
  2. Dim d As Object
  3. Dim x&, y&
  4. Dim arr, brr
  5. Set d = CreateObject("Scripting.Dictionary")

  6. For x = 5 To Cells(Rows.Count, "k").End(3).Row
  7.     d(Cells(x, "k").Value) = Cells(x, "l").Resize(1, 7)
  8.    
  9. Next
  10. For x = 5 To Cells(Rows.Count, "ah").End(3).Row
  11.     d(Cells(x, "ah").Value) = Cells(x, "ai").Resize(1, 7)
  12. Next

  13. arr = d.keys
  14. brr = d.items

  15. For x = 0 To UBound(arr)
  16.     Cells(5 + x, "k") = arr(x)
  17.     For y = 1 To 7
  18.         Cells(5 + x, "k").Offset(0, y) = brr(x)(1, y)
  19.     Next
  20. Next
  21. Set d = Nothing

  22. End Sub

复制代码
回复

使用道具 举报

 楼主| 发表于 2012-8-24 08:08 | 显示全部楼层
zm0115 发表于 2012-8-23 22:20

xx谢谢老师··············!!!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-26 00:09 , Processed in 0.337360 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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