2016-06-21 17 views
0

我對這段代碼的運行時間有困難,大約需要7分鐘才能完成超過20000行的所有公式......是否有任何更改使其運行更快?如何提高此代碼有關公式更新的運行時間?

With Sheets("Rec") 
.Range("A6:A" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=CONCATENATE(RC[1],RC[2],RC[3],RC[4],RC[5],RC[6],RC[7],RC[8])" 
.Range("J6:J" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=SUMIF(CDGL!C[-9],Rec!RC[-9],CDGL!C[29])" 
.Range("K6:K" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=SUMIF(STS!C[-9],Rec!RC[-10],STS!C[28])" 
.Range("L6:L" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=RC[-2]-RC[-1]" 
.Range("M6:M" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=SUMIF(CDGL!C[-12],Rec!RC[-12],CDGL!C[30])" 
.Range("N6:N" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=SUMIF(STS!C[-12],Rec!RC[-13],STS!C[26])" 
.Range("O6:O" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=RC[-2]-RC[-1]" 
End With 

回答

0

我的建議是將自動計算關閉,然後重新打開(一旦代碼完成)。我也將screenupdating設置爲false ...這樣的事情,但在你的代碼的開始。

Application.ScreenUpdating = False 
Application.Calculation = xlCalculationManual 

With Sheets("Rec") 
.Range("A6:A" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=CONCATENATE(RC[1],RC[2],RC[3],RC[4],RC[5],RC[6],RC[7],RC[8])" 
.Range("J6:J" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=SUMIF(CDGL!C[-9],Rec!RC[-9],CDGL!C[29])" 
.Range("K6:K" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=SUMIF(STS!C[-9],Rec!RC[-10],STS!C[28])" 
.Range("L6:L" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=RC[-2]-RC[-1]" 
.Range("M6:M" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=SUMIF(CDGL!C[-12],Rec!RC[-12],CDGL!C[30])" 
.Range("N6:N" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=SUMIF(STS!C[-12],Rec!RC[-13],STS!C[26])" 
.Range("O6:O" & Cells(Rows.Count, "B").End(xlUp).Row + 5).FormulaR1C1 = "=RC[-2]-RC[-1]" 
End With 

Application.Calculation = xlCalculationAutomatic 
Application.ScreenUpdating = True