我希望计算发生在VBA内存中,计算发生后,仅将值粘贴在MS Excel中的一行。
从下面的代码中可以看到,计算发生在单元格内,这很耗时,因为数据非常大。
这是我的代码。
Sub SumIFF()
Dim k As Integer
Dim l As Integer
Dim ws1 As Worksheet
Set ws1 = Worksheets("Input") 'whatever you worksheet is
k = 2 'this is the first row where your data will output
l = 2 'this is the first row where you want to check for data
Do Until Range("A" & l) = "" 'This will loop until column U is empty, set the column to whatever you want but it cannot have blanks in it, or it will stop looping. Choose a column that is always going to have data in it.
ws1.Range("X" & k).FormulaR1C1 = "=SUMIF(R2C21:RC[-3],RC[-3],R2C22:RC[-2])" 'reference SUMIF formula
k = k + 1 'Advances k and l when there is a matching case
l = l + 1
Loop
End Sub
设置应用程序。在执行计算之前ScreenUpdating = False,然后用Application恢复。ScreenUpdating = True - Pieter Geerkens 7月15日22:05