发布网友 发布时间:2022-04-26 02:16
共2个回答
热心网友 时间:2022-06-19 23:46
编写一小段代码可以完成,下图是代码实测结果:
方法:按ALT+F11组合键,打开VB窗口,执行"插入"-"模块",复制下面代码进去,按F5运行程序即得到结果。代码中Range("B3:B14")为原始数据区域,Range("E2")为结果放置区域,按实际更改。
Sub Demo()
Dim Rng As Range
Dim Drng As Range
Dim d As Object
Dim Cell As Range
Set Rng = Range("B3:B14")
Set Drng = Range("E2")
Set d = CreateObject("scripting.dictionary")
For Each Cell In Rng
If Not d.exists(Cell.Value) Then
d(Cell.Value) = Cell.Offset(0, 1).Value
Else
d(Cell.Value) = d(Cell.Value) & "," & Cell.Offset(0, 1).Value
End If
Next
For i = 0 To d.Count - 1
Drng = Filter(d.keys, "")(i)
Drng.Offset(1, 0).Resize(UBound(Split(Filter(d.items, "")(i), ",")) + 1, 1) = Application.Transpose(Split(Filter(d.items, "")(i), ","))
Set Drng = Drng.Offset(0, 1)
Next
End Sub
热心网友 时间:2022-06-19 23:47
E3单元格输入公式=IFERROR(INDEX($B$3:$B$14,SMALL(IF(MATCH($B$3:$B$14,$B$3:$B$14,)=ROW($3:$14)-2,ROW($3:$14)),COLUMN(A1))),"")
数组公式,按Ctrl+Shift+Enter三键结束公式,使公式前后产生大括号{}后,右拉公式。
E4单元格输入公式=IFERROR(INDEX($C$3:$C$14,SMALL(IF($B$3:$B$14=E$3,ROW($3:$14)-2),ROW(A1))),"")
数组公式,按Ctrl+Shift+Enter三键结束公式,使公式前后产生大括号{}后,右拉再下拉公式。 如图:
追问E3单元格在数据比较多的情况下,我右拉公式,为什么会出现重复项?