|
代码如下。。。
Sub test()
Set wb = ThisWorkbook
arr = wb.Sheets("明细").[a1].CurrentRegion
drr = Application.Index(arr, 1)
crr = wb.Sheets("求和").[a1].CurrentRegion
Set d = CreateObject("scripting.dictionary")
ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
For i = 2 To UBound(arr)
s = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(i, 3)
If Not d.exists(s) Then n = n + 1: d(s) = n
m = d(s)
For j = 1 To 3
brr(m, j) = arr(i, j)
Next
For j = 4 To UBound(arr, 2)
brr(m, j) = brr(m, j) + arr(i, j)
Next
Next
For i = 2 To UBound(crr)
s = crr(i, 1) & "|" & crr(i, 2) & "|" & crr(i, 3)
m = d(s)
If m > 0 Then
For j = 4 To UBound(crr, 2)
x = Application.Match(crr(1, j), drr, 0)
If IsNumeric(x) Then crr(i, j) = brr(m, x)
Next
End If
Next
With wb.Sheets("求和")
.[a1].Resize(UBound(crr), UBound(crr, 2)) = crr
End With
Set d = Nothing
Beep
End Sub
|
评分
-
1
查看全部评分
-
|