Excelpromax123
Board Regular
- Joined
- Sep 2, 2021
- Messages
- 167
- Office Version
- 2010
- Platform
- Windows
I have used this code to replace sumif function but the speed is also over 15 seconds. Anyone have a faster solution? Please help me. Sincerely thank
VBA Code:
Sub TestSumIf()
Dim a As Long, b As Long, c As Long, d As Long, F As Long, y As Long, x1 As Long
For x1 = 5 To 10000
a = Application.WorksheetFunction.SumIf(Sheets("data").Range("C4:C10003"), Range("B" & x1), Sheets("data").Range("H4:H10003"))
b = Application.WorksheetFunction.SumIf(Sheets("data").Range("BH2:BH10000"), Range("B" & x1), Sheets("data").Range("BI2:BI10000"))
c = Application.WorksheetFunction.SumIf(Sheets("data").Range("BM2:BM10000"), Range("B" & x1), Sheets("data").Range("BN2:BN10000"))
d = Application.WorksheetFunction.SumIf(Sheets("data").Range("BW102:BW6001"), Range("B" & x1), Sheets("data").Range("BX102:BX6001"))
e = Application.WorksheetFunction.SumIf(Sheets("data").Range("BW102:BW6001"), Range("B" & x1), Sheets("data").Range("BX102:BX6001"))
F = Application.WorksheetFunction.SumIf(Sheets("data").Range("J5:J10004"), Range("B" & x1), Sheets("data").Range("K5:K10004"))
y = a + b - c + d - e + F
Range("d" & x1) = y
Next x1
MsgBox ("OK")
End Sub