使用excel显示重复ID的所有值
我在左边的列A和列B列上有两列,列表A有列表repid,列表b中有相应的值。 我如何筛选列A VALUES并在右侧显示对应的值。
A栏B栏1000 5 1000 ann 2000 chris 2000 56 2001 Beth 3000 Mark 3000 1
输出应显示:ColumnA,B列
1000 5,ann 2000 56,beth 3000 Mark,1
这取决于你确切的情况,但是如果你的A值是升序,你可以这样做:
首先,添加以下macros用于连接:
Function ConCat(Delimiter As Variant, ParamArray CellRanges() As Variant) As String Dim Cell As Range, Area As Variant If IsMissing(Delimiter) Then Delimiter = "" For Each Area In CellRanges If TypeName(Area) = "Range" Then For Each Cell In Area If Len(Cell.Value) Then ConCat = ConCat & Delimiter & Cell.Value Next Else ConCat = ConCat & Delimiter & Area End If Next ConCat = Mid(ConCat, Len(Delimiter) + 1) End Function
然后,在结果列中input以下公式:
=ConCat(",",INDIRECT("B"&MATCH(D3,$A$1:$A$6,0)&":B"&MATCH(D3,$A$1:$A$6,1)))
这基本上findsearch值的第一个和最后一个出现,然后连接该范围内的所有值。
请注意,这是特别为这些单元格中的date:
但是,通过简单地将起始数据行#(使用ROW()函数)添加到匹配结果中,可以轻松修改数据所在的位置。
将其粘贴到列C相关行,并复制剩余的单元格。
=IF(A2=A1,C1&","&B2,B2)
一个使用VBA自动filter的例子。 configuration列A,B,O(输出)的位置,适合的开始和结束行。
Option Explicit Sub xfrMatches() Dim ws As Worksheet Dim colA As Long, colB As Long, strowA, endRowA As Long Dim colO As Long, stRowO As Long, endRowO As Long Dim c As Long Dim crit1 As Variant Dim tmpStr As String Dim cl As Range Set ws = Sheets("Sheet1") colA = 1 colB = 2 strowA = 2 colO = 7 stRowO = 3 ws.AutoFilterMode = False With ws endRowA = .Cells(Rows.Count, colA).End(xlUp).Row endRowO = .Cells(Rows.Count, colO).End(xlUp).Row For c = stRowO To endRowO ws.AutoFilterMode = False crit1 = .Cells(c, colO).Value With .Range(.Cells(strowA, colA), .Cells(endRowA, colB)) .AutoFilter .AutoFilter Field:=1, Criteria1:=crit1 End With With .AutoFilter.Range tmpStr = "" For Each cl In .Columns(colB).Offset(1, 0).SpecialCells(xlCellTypeVisible) tmpStr = tmpStr & "," & cl.Value Next cl ws.AutoFilterMode = False End With .Cells(c, colO).Offset(0, 1).Value = Mid(tmpStr, 2, Len(tmpStr) - 2) Next c End With End Sub