|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub zhengli()
Dim d As Object, dc As Object
Dim ar As Variant
Dim br()
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
ar = Sheet1.[a1].CurrentRegion
For i = 2 To UBound(ar)
If Trim(ar(i, 3)) <> "" Then
d(Trim(ar(i, 3))) = d(Trim(ar(i, 3))) + 1
End If
Next i
ReDim br(1 To UBound(ar), 1 To 5)
For Each k In d.keys
For i = 2 To UBound(ar)
If Trim(ar(i, 3)) = k Then
If Not dc.exists(Trim(ar(i, 4))) Then
dc(Trim(ar(i, 4))) = ar(i, 2)
Else
dc(Trim(ar(i, 4))) = dc(Trim(ar(i, 4))) & "、" & ar(i, 2)
End If
End If
Next i
m = 0
For Each kc In dc.keys
m = m + 1
n = n + 1
If m = 1 Then
br(n, 1) = k
br(n, 2) = d(k)
Else
br(n, 2) = ""
br(n, 1) = ""
End If
br(n, 3) = kc
If InStr(dc(kc), "、") = 0 Then
sl = 1
Else
rr = Split(dc(kc), "、")
sl = UBound(rr) + 1
End If
br(n, 4) = sl
br(n, 5) = dc(kc)
Next kc
dc.RemoveAll
Next k
With Sheet2
.UsedRange.Offset(1).Clear
.[a2].Resize(n, UBound(br, 2)) = br
End With
MsgBox "ok!"
End Sub
|
|