我左边有两列A列和B列COlumn A有重复ID,columb b中有相应的值。如何过滤A VALUES列并在右侧显示它们的相应值。
A栏B栏1000 5 1000安 2000 chris 2000 56 2001 Beth 3000 Mark 3000 1
输出应显示:ColumnA,B列
1000 5,ann 2000 56,beth 3000 Mark,1
答案 0 :(得分:1)
将其粘贴到C列相关行并复制剩余的单元格。
=IF(A2=A1,C1&","&B2,B2)
答案 1 :(得分:0)
这取决于您的具体情况,但如果您的A值按升序排列,则可以执行此操作:
首先,添加以下宏以进行连接:
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
然后,将以下公式放在结果列中:
=ConCat(",",INDIRECT("B"&MATCH(D3,$A$1:$A$6,0)&":B"&MATCH(D3,$A$1:$A$6,1)))
这基本上可以找到搜索值的第一个和最后一个匹配项,然后连接该范围内的所有值。
请注意,这是针对这些单元格中的日期:
但是,只需将起始数据行#(使用ROW()函数)添加到两个匹配结果中,就可以轻松修改数据所在的位置。
答案 2 :(得分:0)
使用VBA自动过滤器的示例。配置Cols 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