Sub 取数()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Dim br()
Set d = CreateObject("scripting.dictionary")
With Sheet1
r = .Cells(Rows.Count, 2).End(xlUp).Row
ar = .Range("a1:e" & r)
ReDim br(1 To 100000, 1 To 3)
For i = 2 To UBound(ar)
If Trim(ar(i, 2)) <> "" Then
If InStr(ar(i, 3), ",") = 0 Then
zf = ar(i, 2) & ar(i, 3)
t = d(zf)
If t = "" Then
k = k + 1
d(zf) = k
t = k
br(k, 1) = zf
End If
br(t, 3) = br(t, 3) + ar(i, 5)
br(t, 2) = ar(i, 4)
ElseIf InStr(ar(i, 3), ",") > 0 Then
rr = Split(ar(i, 3), ",")
sl = UBound(rr) + 1
For s = 0 To UBound(rr)
zf = ar(i, 2) & rr(s)
t = d(zf)
If t = "" Then
k = k + 1
d(zf) = k
t = k
br(k, 1) = zf
End If
br(t, 2) = ar(i, 4)
br(t, 3) = br(t, 3) + (ar(i, 5) / sl)
Next s
End If
End If
Next i
r = .Cells(Rows.Count, 7).End(xlUp).Row
.Range("g2:i" & rs + 1).Borders.LineStyle = 0
.Range("g2:i" & rs + 1) = Empty
.[g2].Resize(k, UBound(br, 2)) = br
.[g2].Resize(k, UBound(br, 2)).Borders.LineStyle = 1
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|