明显的改进是在宏填充公式时关闭屏幕更新和计算,然后在最后重新打开。可能有其他方法可以改善这一点,但我会从这些容易实现的目标开始。
sub test()
Dim Total_Rows As Long
Sheets("Sheet1").Activate
'## Disable screenupdating and calculation
Application.ScreenUpdating = False
Application.Calculation = -4135 xlCalculationManual
Total_Rows = 13000
Range("C2", "C" & Total_Rows) = "=SUMIFS('Sheet2'!C:C,'Sheet2'!A:A,'Sheet2!A2)"
'## Put the calculation back to Automatic
Application.Calculation = -4105 'xlCalculationAutomatic
ActiveSheet.Calculate 'Force a calculation
'## Replace the formulas with values only:
Range("C2", "C" & Total_Rows).Value = Range("C2", "C" & Total_Rows).Value
'## Allow the screen to update
Application.ScreenUpdating = True
End Sub