|
楼主 |
发表于 2018-8-15 22:44
|
显示全部楼层
我之前写一个SUMIF的宏,速度太慢了,有人告诉我可用数组,我就写了这个,其实自已不是很清楚。
之前写的是这个
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) 'Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
StartTime = Timer
Dim i As Variant, x As Variant
x = [a65536].End(xlUp).Row
For i = 2 To x
x = WorksheetFunction.SumIf(Sheet6.Range("b2:b" & i), Cells(i, 1).Value, Sheet6.Range("c2:c" & i))
If x > 0 Then
Cells(i, 5) = Application.WorksheetFunction.CountIf(Range(Cells(1, 1), Cells(i, 1)), Cells(i, 1))
Else
Cells(i, 5) = ""
End If
Cells(i, 4) = Application.WorksheetFunction.CountIf(Range(Cells(1, 5), Cells(i, 5)), Cells(i, 5))
'Cells(i, 6) = Cells(i, 1)
'Cells(i, 5) = Format(Cells(i, 7), "yyyymm") & Cells(i, 10)
Next i
'Application.ScreenUpdating = True
MsgBox "花费" & Timer - StartTime & "秒"
End Sub
|
|