本帖最后由 longming3 于 2018-9-15 17:23 编辑
Sub aa()
ar = Sheets("数据表").Range("a1").CurrentRegion
With Sheets("VBA查询")
cxrq = .[a1]
Set d = CreateObject("Scripting.Dictionary")
For i = 2 To UBound(ar)
If ar(i, 1) = cxrq Then
s = ar(i, 2) & "#" & ar(i, 5)
d(ar(i, 3)) = d(ar(i, 3)) & "/" & s
End If
Next
kk = d.keys: tt = d.items
ReDim br(1 To UBound(ar), 1 To 6)
For i = 0 To d.Count - 1
k = k + 1
w = ""
x = Split(tt(i), "/")
For j = 1 To UBound(x)
m = Split(x(j), "#")
If w <> "" And w <> m(0) Then
br(k, 1) = br(k, 1) & "/" & m(0)
br(k, 3) = br(k, 3) & "/" & m(1)
br(k, 4) = br(k, 4) + 1
fj = Split(br(k, 3), "/")
For y = 0 To UBound(fj)
cl = cl & "/" & Val(fj(y)) / br(k, 4)
Next
br(k, 5) = Mid(cl, 2, Len(cl) - 1)
br(k, 6) = kk(i)
cl = ""
Else
br(k, 1) = m(0)
br(k, 3) = br(k, 3) + Val(m(1))
br(k, 4) = br(k, 4) + 1
br(k, 5) = br(k, 3) / br(k, 4)
br(k, 6) = kk(i)
End If
w = br(k, 1)
Next
Next
.[j3].Resize(k, 6) = br
End With
End Sub
|