|
以下是第一次写的一段代码(刚开始学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
|
|