Excel精英培训网

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

[已解决]这段代码有办法优化吗?

[复制链接]
发表于 2011-12-11 12:31 | 显示全部楼层 |阅读模式
  1. Sub in11()
  2. x2 = TextBox2
  3. Select Case x2
  4. Case Is = 1
  5. [E6] = Locate2
  6. [E7] = spec2
  7. [E8] = size2
  8. [E9] = Series2
  9. [E10] = Part2



  10. Case Is = 2
  11. [e6:f6] = Locate2
  12. [e7:f7] = spec2
  13. [e8:f8] = size2
  14. [e9:f9] = Series2
  15. [e10:f10] = Part2




  16. Case Is = 3
  17. [e6:g6] = Locate2
  18. [e7:g7] = spec2
  19. [e8:g8] = size2
  20. [e9:g9] = Series2
  21. [e10:g10] = Part2

  22. Case Is = 4
  23. [e6:h6] = Locate2
  24. [e7:h7] = spec2
  25. [e8:h8] = size2
  26. [e9:h9] = Series2
  27. [e10:h10] = Part2

  28. Case Is = 5
  29. [e6:i6] = Locate2
  30. [e7:i7] = spec2
  31. [e8:i8] = size2
  32. [e9:i9] = Series2
  33. [e10:i10] = Part2

  34. Case Is >= 6

  35. Call max

  36. End Select

  37. End Sub
复制代码

最佳答案
2011-12-11 13:51
  1. Sub in11()
  2. X2 = TextBox2
  3. If X2 < 6 Then
  4.     Range(Cells(6, 5), Cells(6, X2 + 4)) = Locate2
  5.     Range(Cells(7, 5), Cells(7, X2 + 4)) = spec2
  6.     Range(Cells(8, 5), Cells(8, X2 + 4)) = size2
  7.     Range(Cells(9, 5), Cells(9, X2 + 4)) = Series2
  8.     Range(Cells(10, 5), Cells(10, X2 + 4)) = Part2
  9. Else
  10.     Call Max
  11. End If
  12. End Sub
复制代码
发表于 2011-12-11 12:51 | 显示全部楼层
将你的功能要求发一下,未必你的代码思路就是最佳的。
回复

使用道具 举报

发表于 2011-12-11 13:51 | 显示全部楼层    本楼为最佳答案   
  1. Sub in11()
  2. X2 = TextBox2
  3. If X2 < 6 Then
  4.     Range(Cells(6, 5), Cells(6, X2 + 4)) = Locate2
  5.     Range(Cells(7, 5), Cells(7, X2 + 4)) = spec2
  6.     Range(Cells(8, 5), Cells(8, X2 + 4)) = size2
  7.     Range(Cells(9, 5), Cells(9, X2 + 4)) = Series2
  8.     Range(Cells(10, 5), Cells(10, X2 + 4)) = Part2
  9. Else
  10.     Call Max
  11. End If
  12. End Sub
复制代码
回复

使用道具 举报

发表于 2011-12-11 13:54 | 显示全部楼层
  1. Sub in11()
  2. X2 = TextBox2
  3. If X2 < 6 Then
  4.     Range("E6").Resize(, X2) = Locate2
  5.     Range("E7").Resize(, X2) = spec2
  6.     Range("E8").Resize(, X2) = size2
  7.     Range("E9").Resize(, X2) = Series2
  8.     Range("E10").Resize(, X2) = Part2
  9. Else
  10.     Call Max
  11. End If
  12. End Sub
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-14 05:35 , Processed in 0.260308 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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