粘贴宏 - 增加速度

时间:2013-12-30 18:37:32

标签: vba excel-vba excel-formula excel

如何让这个宏更快?

窗( “该”)。激活     表( “THE2”)。选择

Range("H8").Select
ActiveCell.FormulaR1C1 = _
    "=SUMIFS('Google'!C8,'Googe'!C1,RC21,'Google'!C5,RC1)"
Range("H8").Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste

1 个答案:

答案 0 :(得分:3)

1)Avoid using Select/Active statements

2)使用With block

3)立即将公式应用于整个范围(而不是复制/粘贴)

With Workbooks("THe").Sheets("The2")
    .Range("H8:H" & .Cells(.Rows.Count, "H").End(xlUp).Row).FormulaR1C1 = _
        "=SUMIFS('Google'!C8,'Googe'!C1,RC21,'Google'!C5,RC1)"
End With

并且也不使用xlDown,而是使用xlUpHow to determine last used row/column