Sub test()
With New Scripting.Dictionary
Dim cel As Range
For Each cel In Range("A1").CurrentRegion
If Not .Exists(Split(cel.Value, ".")(1)) Then .Add Split(cel.Value, ".")(1), New Scripting.Dictionary
.Item(Split(cel.Value, ".")(1)).Add cel.Value, 1
Next
Dim iK As Long
For iK = 0 To .Count - 1
Range("C1").Offset(, iK).Resize(.Items(iK).Count).Value = Application.Transpose(.Items(iK).Keys)
Next
End With
End Sub
Sub test()
Dim dic As Object
Set dic = CreateObject("Scripting.Dictionary")
dic.comparemode = vbTextCompare
Dim cl As Range
For Each cl In [A1:A6]
If Not dic.exists(Split(cl.Value, ".")(1)) Then
dic.Add Split(cl.Value, ".")(1), cl.Value
Else
dic(Split(cl.Value, ".")(1)) = dic(Split(cl.Value, ".")(1)) & "|" & cl.Value
End If
Next cl
Dim x%, i%, dKey, sVal
x = 3
For Each dKey In dic
i = 1
For Each sVal In Split(dic(dKey), "|")
Cells(i, x).Value = sVal
i = i + 1
Next sVal
x = x + 1
Next dKey
End Sub
3条答案
按热度按时间e0bqpujr1#
拆分和分组
如果您有Microsoft 365,则可以使用以下各项:
如果要添加标头,请添加
TOROW
和VSTACK
:TEXTAFTER
。TOROW
。5w9g7ksd2#
可以使用嵌套字典
只需添加对"Microsoft脚本运行时"库的引用
第一节第一节第一节第一节第一次
7lrncoxx3#
使用
scripting.dictionary
的变体:演示: