我对此代码的运行时间有困难,大约需要7分钟才能完成超过20,000行的所有公式...是否有任何改动以使其运行更快?
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 :(得分: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