ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

求助:为什么这个代码运行速度这么慢?怎么解决?

[复制链接]

TA的精华主题

TA的得分主题

发表于 2014-12-12 13:17 | 显示全部楼层 |阅读模式
以下是第一次写的一段代码(刚开始学VBA),"Input“页,每一行是一个产品的参数,把每个产品的参数调到" Part level cost"页参与计算,计算的结果输出到"output"页。但是不知道什么原因,运算速度很慢,算40个产品要花几分钟的时间,请高手看看到底问题在什么地方? 先谢了!


Sub Button65_Click()
Worksheets("output").Range("A3:BW203").ClearContents
Application.ScreenUpdating = False
Dim NbLines As Integer
Dim i As Integer
NbLines = Worksheets("Input").Range("A500").End(xlUp).Row
Worksheets("Input").Cells(1, 8).Value = NbLines - 5

For i = 6 To NbLine
     
     Worksheets("Part level cost").Cells(3, 1).Value = Worksheets("Input").Cells(i, 1).Value
    Worksheets("Part level cost").Cells(3, 2).Value = Worksheets("Input").Cells(i, 2).Value
    Worksheets("Part level cost").Cells(3, 3).Value = Worksheets("Input").Cells(i, 3).Value
    Worksheets("Part level cost").Cells(3, 4).Value = Worksheets("Input").Cells(i, 4).Value
    Worksheets("Part level cost").Cells(3, 5).Value = Worksheets("Input").Cells(i, 5).Value
    Worksheets("Part level cost").Cells(3, 8).Value = Worksheets("Input").Cells(i, 6).Value
    Worksheets("Part level cost").Cells(3, 6).Value = Worksheets("Input").Cells(i, 7).Value
    Worksheets("Part level cost").Cells(3, 7).Value = Worksheets("Input").Cells(i, 8).Value
    Worksheets("Part level cost").Cells(3, 9).Value = Worksheets("Input").Cells(i, 9).Value
    Worksheets("Part level cost").Cells(4, 10).Value = Worksheets("Input").Cells(i, 14).Value
    Worksheets("Part level cost").Cells(3, 12).Value = Worksheets("Input").Cells(i, 16).Value
    Worksheets("Part level cost").Cells(3, 13).Value = Worksheets("Input").Cells(i, 15).Value
    Worksheets("Part level cost").Cells(3, 14).Value = Worksheets("Input").Cells(i, 17).Value
    Worksheets("Part level cost").Cells(4, 15).Value = Worksheets("Input").Cells(i, 20).Value
    Worksheets("Part level cost").Cells(3, 16).Value = Worksheets("Input").Cells(i, 18).Value
    Worksheets("Part level cost").Cells(4, 19).Value = Worksheets("Input").Cells(i, 21).Value
    Worksheets("Part level cost").Cells(3, 20).Value = Worksheets("Input").Cells(i, 10).Value
    Worksheets("Part level cost").Cells(3, 21).Value = Worksheets("Input").Cells(i, 19).Value
    Worksheets("Part level cost").Cells(4, 26).Value = Worksheets("Input").Cells(i, 22).Value
    Worksheets("Part level cost").Cells(3, 27).Value = Worksheets("Input").Cells(i, 12).Value
    Worksheets("Part level cost").Cells(3, 28).Value = Worksheets("Input").Cells(i, 13).Value
    Worksheets("Part level cost").Cells(3, 30).Value = Worksheets("Input").Cells(i, 11).Value
    Worksheets("Part level cost").Cells(4, 56).Value = Worksheets("Input").Cells(i, 23).Value
    Worksheets("Part level cost").Cells(4, 59).Value = Worksheets("Input").Cells(i, 24).Value
    Worksheets("Part level cost").Cells(4, 62).Value = Worksheets("Input").Cells(i, 26).Value
    Worksheets("Part level cost").Cells(4, 67).Value = Worksheets("Input").Cells(i, 25).Value
    Worksheets("Part level cost").Cells(3, 73).Value = Worksheets("Input").Cells(i, 28).Value
   
   
  Range("A2").Select
    Sheets("output").Select
    Rows((i - 3) & ":" & (i - 3)).Select
    Sheets("Part level cost").Select
    Range("A3:BW3").Select
    Selection.Copy
    Sheets("output").Select
    Range("A" & (i - 3)).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
Next i
Application.ScreenUpdating = True

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

本版积分规则

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

GMT+8, 2024-11-22 23:48 , Processed in 0.030890 second(s), 7 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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