|
代码如下:
Sub 结果表降重()
Dim r As Long
Dim ar, brr, arr2
Dim dic_cs As Object
With Sheet3
r = .[d1].End(4).Row
Set dic_cs = CreateObject("Scripting.Dictionary")
brr = .Range("a2:d" & r).Value
.Range("a2:d" & r).ClearContents
For i = 1 To UBound(brr) - 1
If dic_cs.exists(brr(i, 1) & "+" & brr(i, 2) & "+" & brr(i, 3)) Then
dic_cs(brr(i, 1) & "+" & brr(i, 2) & "+" & brr(i, 3)) = Val(brr(i, 4)) + dic_cs(brr(i, 1) & "+" & brr(i, 2) & "+" & brr(i, 3))
Else
dic_cs(brr(i, 1) & "+" & brr(i, 2) & "+" & brr(i, 3)) = brr(i, 4)
End If
Next
k1 = dic_cs.Keys
t1 = dic_cs.Items
n1 = dic_cs.Count
ReDim arr2(n1, 3)
For i = 0 To n1 - 1
ar = Split(k1(i), "+")
arr2(i, 0) = ar(0)
arr2(i, 1) = ar(1)
arr2(i, 2) = ar(2)
Next
.[a2].Resize(n1, 3) = arr2
.[D2].Resize(n1, 1) = Application.Transpose(t1)
End With
End Sub
运行时, If dic_cs.exists(brr(i, 1) & "+" & brr(i, 2) & "+" & brr(i, 3)) Then 这里提示类型不匹配,鼠标悬停发现brr(i,1)等值为空,但是添加监视时发现brr里面是有值的,请教这种情况是什么原因,如何解决。
|
|