|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 everbest2015 于 2018-10-13 12:20 编辑
Sub 格式转换()
Dim d As Object, ar, br(), i&, k&, m&, x, s
Dim rr, t, n&
Set d = CreateObject("Scripting.Dictionary")
ar = Range("a1").CurrentRegion
For i = 2 To UBound(ar)
s = ar(i, 1)
If Not d.exists(s) Then
d(s) = ar(i, 2)
Else
d(s) = d(s) & ", " & ar(i, 2)
End If
Next
ReDim br(1 To UBound(ar), 1 To d.Count)
[E2].Resize(, 3) = application.transpose(Application.Transpose(d.keys))
For Each x In d.keys
n = n + 1
rr = Split(d(x), ", ")
For Each t In rr
m = m + 1
br(m, n) = rr(m - 1)
Next
m = 0
Next
Stop
[E3].Resize(UBound(ar), 3) = br
End Sub |
|