|
Sub chaxun() '多条件求和
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
For j = 4 To 6
s2 = Sheet2.Cells(j, 2).Value
For x = 3 To 33
s3 = Sheet2.Cells(3, x).Value
Sheet2.Cells(j, x) = IIf(dic(s2 & s3), dic(s2 & s3), 0)
Sheet2.Cells(j, "AH").Value = Sheet2.Cells(j, "AH").Value + Sheet2.Cells(j, x).Value
Next
Next
Range("C9").FormulaR1C1 = "=SUM(R[-5]C:R[-1]C)"
Range("C9").AutoFill Destination:=Range("C9:AH9"), Type:=xlFillDefault
End Sub |
|