|
换个思路,精简了代码
Sub test()
Dim d As Object
Dim br()
Set d = CreateObject("scripting.dictionary")
With Sheet1
ws = .Cells(Rows.Count, 2).End(xlUp).Row
ar = .Range("b1:d" & ws)
.Range("h2:y" & UBound(ar)) = Empty
kk = 1: k = 1
ReDim Preserve br(1 To UBound(ar), 1 To kk)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
t = d(Trim(ar(i, 1)))
If t = "" Then
k = k + 1
d(Trim(ar(i, 1))) = k
t = k
br(k, 1) = ar(i, 1)
End If
s_1 = Format(ar(i, 2), "yyyym")
If Not d.exists(s_1) Then
kk = kk + 1
ReDim Preserve br(1 To UBound(ar), 1 To kk)
br(1, kk) = s_1
br(t, kk) = ar(i, 3)
d(s_1) = kk
ElseIf d.exists(s_1) Then
br(t, d(s_1)) = br(t, d(s_1)) + ar(i, 3)
End If
End If
Next i
.Range("g1").Resize(k, kk) = br
End With
MsgBox "ok!"
End Sub
|
|