|
- Sub 条件求和()
- Dim dic As Object
- Set dic = CreateObject("scripting.dictionary")
- arr = Sheet2.Range("a1").CurrentRegion
- For i = 2 To UBound(arr)
- If Len(arr(i, 1)) > 0 Then
- Key = arr(i, 1) & ""
- dic(Key) = dic(Key) + Val(arr(i, 2))
- End If
- Next
- brr = Sheet1.Range("A1:B" & Sheet1.Cells(Rows.Count, 1).End(xlUp).Row) '数据源装入数组
- For i = 2 To UBound(brr)
- If brr(i, 1) <> "" Then
- Key = brr(i, 1) & ""
- If dic.Exists(Key) Then
- brr(i, 2) = dic(Key)
- End If
- End If
- Next
- Sheet1.Range("a1").Resize(UBound(brr), UBound(brr, 2)) = brr
- End Sub
复制代码 |
|