|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub qs() '多条件求和2024/6/27
Dim arr: arr = Sheet1.UsedRange
Dim dic: Set dic = CreateObject("scripting.dictionary")
Sheet2.Range("c4:ah9").Value = ""
For i = 1 To UBound(arr)
s = arr(i, 2) & arr(i, 4)
If Not dic.exists(s) Then
dic(s) = arr(i, 3)
Else
dic(s) = dic(s) + arr(i, 3)
End If
Next
With Sheet2
Dim brr: brr = .Range("b3:ah9")
For j = 2 To UBound(brr) - 1
If brr(j, 1) <> "" Then
s2 = brr(j, 1)
For x = 2 To UBound(brr, 2) - 1
s3 = brr(1, x)
brr(j, x) = IIf(dic(s2 & s3), dic(s2 & s3), 0)
sm = sm + brr(j, x)
Next
End If
brr(j, UBound(brr, 2)) = sm
sm = 0
Next
.Range("b3").Resize(UBound(brr), UBound(brr, 2)) = brr
Range("C9").FormulaR1C1 = "=SUM(R[-5]C:R[-1]C)"
Range("C9").AutoFill Destination:=Range("C9:AH9"), Type:=xlFillDefault
End With
End Sub |
|