Excel精英培训网

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

[已解决]帮忙改一下这个代码,很有规律

[复制链接]
发表于 2011-12-28 21:51 | 显示全部楼层 |阅读模式
  1. Sub P1()
  2. Dim x As Integer
  3. Call Module3.che

  4. For x = 3 To 7
  5. Range(Cells(6, 4), Cells(x + 3, 4)) = UserForm1.T1

  6. Range(Cells(7, 4), Cells(x + 3, 4)) = UserForm1.T2

  7. Range(Cells(8, 4), Cells(x + 3, 4)) = UserForm1.T3

  8. Range(Cells(9, 4), Cells(x + 3, 4)) = UserForm1.T4

  9. Range(Cells(10, 4), Cells(x + 3, 4)) = UserForm1.T5



  10. Range(Cells(6, 5), Cells(x + 3, 5)) = UserForm1.T6

  11. Range(Cells(7, 5), Cells(x + 3, 5)) = UserForm1.T7

  12. Range(Cells(8, 5), Cells(x + 3, 5)) = UserForm1.T8

  13. Range(Cells(9, 5), Cells(x + 3, 5)) = UserForm1.T9

  14. Range(Cells(10, 5), Cells(x + 3, 5)) = UserForm1.T10



  15. Range(Cells(6, 6), Cells(x + 3, 6)) = UserForm1.T11

  16. Range(Cells(7, 6), Cells(x + 3, 6)) = UserForm1.T12

  17. Range(Cells(8, 6), Cells(x + 3, 6)) = UserForm1.T13

  18. Range(Cells(9, 6), Cells(x + 3, 6)) = UserForm1.T14

  19. Range(Cells(10, 6), Cells(x + 3, 6)) = UserForm1.T15



  20. Range(Cells(6, 7), Cells(x + 3, 7)) = UserForm1.T16

  21. Range(Cells(7, 7), Cells(x + 3, 7)) = UserForm1.T17

  22. Range(Cells(8, 7), Cells(x + 3, 7)) = UserForm1.T18

  23. Range(Cells(9, 7), Cells(x + 3, 7)) = UserForm1.T19

  24. Range(Cells(10, 7), Cells(x + 3, 7)) = UserForm1.T20



  25. Range(Cells(6, 8), Cells(x + 3, 8)) = UserForm1.T21

  26. Range(Cells(7, 8), Cells(x + 3, 8)) = UserForm1.T22

  27. Range(Cells(8, 8), Cells(x + 3, 8)) = UserForm1.T23

  28. Range(Cells(9, 8), Cells(x + 3, 8)) = UserForm1.T24

  29. Range(Cells(10, 8), Cells(x + 3, 8)) = UserForm1.T25



  30. Range(Cells(6, 9), Cells(x + 3, 9)) = UserForm1.T26

  31. Range(Cells(7, 9), Cells(x + 3, 9)) = UserForm1.T27

  32. Range(Cells(8, 9), Cells(x + 3, 9)) = UserForm1.T28

  33. Range(Cells(9, 9), Cells(x + 3, 9)) = UserForm1.T29

  34. Range(Cells(10, 9), Cells(x + 3, 9)) = UserForm1.T30


  35. Range(Cells(6, 10), Cells(x + 3, 10)) = UserForm1.T31

  36. Range(Cells(7, 10), Cells(x + 3, 10)) = UserForm1.T32

  37. Range(Cells(8, 10), Cells(x + 3, 10)) = UserForm1.T33

  38. Range(Cells(9, 10), Cells(x + 3, 10)) = UserForm1.T34

  39. Range(Cells(10, 10), Cells(x + 3, 10)) = UserForm1.T35



  40. Range(Cells(6, 11), Cells(x + 3, 11)) = UserForm1.T36

  41. Range(Cells(7, 11), Cells(x + 3, 11)) = UserForm1.T37

  42. Range(Cells(8, 11), Cells(x + 3, 11)) = UserForm1.T38

  43. Range(Cells(9, 11), Cells(x + 3, 11)) = UserForm1.T39

  44. Range(Cells(10, 11), Cells(x + 3, 11)) = UserForm1.T40



  45. Range(Cells(6, 12), Cells(x + 3, 12)) = UserForm1.T41

  46. Range(Cells(7, 12), Cells(x + 3, 12)) = UserForm1.T42

  47. Range(Cells(8, 12), Cells(x + 3, 12)) = UserForm1.T43

  48. Range(Cells(9, 12), Cells(x + 3, 12)) = UserForm1.T44

  49. Range(Cells(10, 12), Cells(x + 3, 12)) = UserForm1.T45

  50. Next
  51. End Sub
复制代码

最佳答案
2011-12-28 23:33
本帖最后由 Zipall 于 2011-12-28 23:33 编辑
443233785 发表于 2011-12-28 23:13
请看附件,谢谢

改3处,我用红色标记出

    For x = 3 To 7
        For j = 4 To 12
            For i = 6 To 10
                t = t + 1
                Range(Cells(i, j), Cells(x + 3, j)) = UserForm1.Controls("T" & t)
            Next
        Next
        t = 0
    Next



excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2011-12-28 22:07 | 显示全部楼层
本帖最后由 Zipall 于 2011-12-28 22:09 编辑

Sub P1()
    Dim x As Integer, i As Integer, j As Integer, t As Integer
    Call Module3.che

    For x = 3 To 7
        For i = 6 To 10
            For j = 4 To 12
                t = t + 1
                Range(Cells(i, j), Cells(x + 3, j)) = UserForm1.Controls("T" & i)
            Next
        Next
        t = 0
    Next

End Sub


评分

参与人数 1 +15 收起 理由
windimi007 + 15 要用到Controls呀!怪不得我怎么试都不对,.

查看全部评分

回复

使用道具 举报

发表于 2011-12-28 22:17 | 显示全部楼层
本帖最后由 windimi007 于 2011-12-28 22:19 编辑
Zipall 发表于 2011-12-28 22:07
Sub P1()
    Dim x As Integer, i As Integer, j As Integer, t As Integer
    Call Module3.che


猫哥,问个问题:
  1. UserForm1.T1
复制代码


表示什么?{:4512:}

回复

使用道具 举报

发表于 2011-12-28 22:21 | 显示全部楼层
windimi007 发表于 2011-12-28 22:17
猫哥,问个问题:

我猜T1是个textbox的name.
回复

使用道具 举报

发表于 2011-12-28 22:26 | 显示全部楼层
Zipall 发表于 2011-12-28 22:21
我猜T1是个textbox的name.

猫哥应该猜得没错!{:912:}
回复

使用道具 举报

 楼主| 发表于 2011-12-28 22:49 | 显示全部楼层
windimi007 发表于 2011-12-28 22:26
猫哥应该猜得没错!

没错,是的            
回复

使用道具 举报

 楼主| 发表于 2011-12-28 23:01 | 显示全部楼层
Zipall 发表于 2011-12-28 22:07
Sub P1()
    Dim x As Integer, i As Integer, j As Integer, t As Integer
    Call Module3.che

代码好像不行喔,您再仔细看看呢,运行结果不一样
回复

使用道具 举报

发表于 2011-12-28 23:07 | 显示全部楼层
本帖最后由 Zipall 于 2011-12-28 23:09 编辑
443233785 发表于 2011-12-28 23:01
代码好像不行喔,您再仔细看看呢,运行结果不一样
把for i  for j 两句交换下顺序.
或者给个供测试的文件先.
回复

使用道具 举报

 楼主| 发表于 2011-12-28 23:13 | 显示全部楼层

请看附件,谢谢

本帖最后由 443233785 于 2011-12-28 23:40 编辑
Zipall 发表于 2011-12-28 23:07
把for i  for j 两句交换下顺序.
或者给个供测试的文件先.


大                                                                                               
回复

使用道具 举报

发表于 2011-12-28 23:33 | 显示全部楼层    本楼为最佳答案   
本帖最后由 Zipall 于 2011-12-28 23:33 编辑
443233785 发表于 2011-12-28 23:13
请看附件,谢谢

改3处,我用红色标记出

    For x = 3 To 7
        For j = 4 To 12
            For i = 6 To 10
                t = t + 1
                Range(Cells(i, j), Cells(x + 3, j)) = UserForm1.Controls("T" & t)
            Next
        Next
        t = 0
    Next



回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-17 23:52 , Processed in 0.317959 second(s), 13 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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