ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

求助简化代码的方法.下面是根据单元格数值变化逐次递增显示图片的代码,很慢,求助.

[复制链接]

TA的精华主题

TA的得分主题

发表于 2013-3-4 12:19 | 显示全部楼层 |阅读模式
Image158.Visible = False
Image67.Visible = False
Image60.Visible = False
Image56.Visible = False
Image86.Visible = False
Image82.Visible = False
Image81.Visible = False
Image18.Visible = False
Image2.Visible = False
Image17.Visible = False
Image3.Visible = False
Image14.Visible = False
Image4.Visible = False
Image12.Visible = False
Image5.Visible = False
Image11.Visible = False
Image6.Visible = False
Image10.Visible = False
Image7.Visible = False
Image9.Visible = False
Image8.Visible = False
If [G2].Value = 1 Then
Image8.Visible = True
ElseIf [G2].Value = 2 Then
Image9.Visible = True
Image8.Visible = True

ElseIf [G2].Value = 3 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
ElseIf [G2].Value = 4 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
ElseIf [G2].Value = 5 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
ElseIf [G2].Value = 6 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
ElseIf [G2].Value = 7 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
ElseIf [G2].Value = 8 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image12.Visible = True
ElseIf [G2].Value = 9 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image12.Visible = True
Image4.Visible = True
ElseIf [G2].Value = 10 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image4.Visible = True
Image12.Visible = True
Image14.Visible = True
ElseIf [G2].Value = 11 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image4.Visible = True
Image14.Visible = True
Image12.Visible = True
Image3.Visible = True
ElseIf [G2].Value = 12 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image12.Visible = True
Image4.Visible = True
Image14.Visible = True
Image3.Visible = True
Image17.Visible = True
ElseIf [G2].Value = 13 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image12.Visible = True
Image4.Visible = True
Image14.Visible = True
Image3.Visible = True
Image17.Visible = True
Image2.Visible = True
ElseIf [G2].Value = 14 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image12.Visible = True
Image4.Visible = True
Image14.Visible = True
Image3.Visible = True
Image17.Visible = True
Image2.Visible = True
Image18.Visible = True
ElseIf [G2].Value = 15 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image12.Visible = True
Image4.Visible = True
Image14.Visible = True
Image3.Visible = True
Image17.Visible = True
Image2.Visible = True
Image18.Visible = True
Image81.Visible = True
ElseIf [G2].Value = 16 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image12.Visible = True
Image4.Visible = True
Image14.Visible = True
Image3.Visible = True
Image17.Visible = True
Image2.Visible = True
Image18.Visible = True
Image81.Visible = True
Image82.Visible = True
ElseIf [G2].Value = 17 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image12.Visible = True
Image4.Visible = True
Image14.Visible = True
Image3.Visible = True
Image17.Visible = True
Image2.Visible = True
Image18.Visible = True
Image81.Visible = True
Image82.Visible = True
Image86.Visible = True
ElseIf [G2].Value = 18 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image12.Visible = True
Image4.Visible = True
Image14.Visible = True
Image3.Visible = True
Image17.Visible = True
Image2.Visible = True
Image18.Visible = True
Image81.Visible = True
Image82.Visible = True
Image86.Visible = True
Image56.Visible = True
ElseIf [G2].Value = 19 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image12.Visible = True
Image4.Visible = True
Image14.Visible = True
Image3.Visible = True
Image17.Visible = True
Image2.Visible = True
Image18.Visible = True
Image81.Visible = True
Image82.Visible = True
Image86.Visible = True
Image56.Visible = True
Image60.Visible = True
ElseIf [G2].Value = 20 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image12.Visible = True
Image4.Visible = True
Image14.Visible = True
Image3.Visible = True
Image17.Visible = True
Image2.Visible = True
Image18.Visible = True
Image81.Visible = True
Image82.Visible = True
Image86.Visible = True
Image56.Visible = True
Image60.Visible = True
Image67.Visible = True
ElseIf [G2].Value = 21 Then
Image9.Visible = True
Image8.Visible = True
Image7.Visible = True
Image10.Visible = True
Image6.Visible = True
Image11.Visible = True
Image5.Visible = True
Image12.Visible = True
Image4.Visible = True
Image14.Visible = True
Image3.Visible = True
Image17.Visible = True
Image2.Visible = True
Image18.Visible = True
Image81.Visible = True
Image82.Visible = True
Image86.Visible = True
Image56.Visible = True
Image60.Visible = True
Image67.Visible = True
Image158.Visible = True
Else
Image158.Visible = False
Image67.Visible = False
Image60.Visible = False
Image56.Visible = False
Image86.Visible = False
Image82.Visible = False
Image81.Visible = False
Image18.Visible = False
Image2.Visible = False
Image17.Visible = False
Image3.Visible = False
Image14.Visible = False
Image4.Visible = False
Image12.Visible = False
Image5.Visible = False
Image11.Visible = False
Image6.Visible = False
Image10.Visible = False
Image7.Visible = False
Image9.Visible = False
Image8.Visible = False

TA的精华主题

TA的得分主题

发表于 2013-3-4 12:34 | 显示全部楼层
讲规律吧
每条代码进行一次对象操作,慢并不在代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2013-3-4 12:42 | 显示全部楼层
李甲 发表于 2013-3-4 12:34
讲规律吧
每条代码进行一次对象操作,慢并不在代码

你好,您说讲规律是何意呢,如何编写代码?我其实是在做一个工厂的各种设备流程图,根据工艺计算得出的设备台数后(某个单元格数值),通过按钮控制有关image图片在表格中显示出来,显示的数量与台数相同.这样的代码是很有规律,比如设备台数为1,就显示一张设备图片,为5,就显示5张,以此类推.
问题是如果仅仅是上面的一组代码,速度也不算慢,计算下来三秒左右,但我后面还有四种设备也需要同样的代码来显示台数,这时候如果进行计算,要25秒左右,有些长了,不知道如何解决.

TA的精华主题

TA的得分主题

发表于 2013-3-4 13:00 | 显示全部楼层
写的太辛苦了!你把附件上传,别人才能帮你优化。

TA的精华主题

TA的得分主题

发表于 2013-3-4 13:09 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
附件传上,用循环吧,这样看起来都很累!!!

TA的精华主题

TA的得分主题

 楼主| 发表于 2013-3-4 14:00 | 显示全部楼层
各位专家,附件已上传,附件里面就是希望通过单元格数值的变化(也就是设备台数)来控制对应数量图片的显示,由于其中干燥机,破碎机和成型机的台数都比较多,故在进行计算时候需要很长时间,我是vba初学者,不知道如何处理,求专家指点如何优化代码才能才能提高运行速度,不胜感谢!

附件-图片控制代码求助简化提速.part07.rar

140.55 KB, 下载次数: 5

附件-图片控制代码求助简化提速.part06.rar

240 KB, 下载次数: 3

附件-图片控制代码求助简化提速.part05.rar

240 KB, 下载次数: 3

附件-图片控制代码求助简化提速.part04.rar

240 KB, 下载次数: 3

附件-图片控制代码求助简化提速.part03.rar

240 KB, 下载次数: 3

附件-图片控制代码求助简化提速.part02.rar

240 KB, 下载次数: 3

附件-图片控制代码求助简化提速.part01.rar

240 KB, 下载次数: 6

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

本版积分规则

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

GMT+8, 2024-11-23 05:40 , Processed in 0.032875 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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