我正在尝试找到一种方法从数组中获取多个值以在一个单元格中显示
比如说我有两列如下
1
b 2
c 1
d 3
e 2
我希望所有值都形成第一列,其中第二列是1
vlookup和带匹配的索引都只提供第一个匹配的实例,有没有办法用函数执行此操作,还是必须在带有VBA的宏中创建?
由于
答案 0 :(得分:1)
如果您希望所有结果都显示在一个单元格中,您可以使用该VBA公式:
'r is the range of cells that you have a value to look for
'v is the value you are looking for
Function getValues(r As Range, v As Variant)
Dim c As Range
getValues = ""
For Each c In r
If c.Value = v Then
If getValues = "" Then
'Offset(0,-1) will give you value from previous coulmn
getValues = c.Offset(0, -1).Value
Else
getValues = getValues & "," & c.Offset(0, -1).Value
End If
End If
Next c
End Function
使用示例:在单元格C1中输入此=getValues(B1:B5,1)
答案 1 :(得分:0)
考虑到您的数据在A1:B5
范围内,Cell C1
包含您要查找的数字。
在Cell D1
中输入以下数组公式,然后根据需要向下拖动/复制到该行。
=IFERROR(INDEX($A$1:$A$5, SMALL(IF($C$1=$B$1:$B$5, ROW($B$1:$B$5)-MIN(ROW($B$1:$B$5))+1, ""), ROW(A1))), "")
作为数组公式,您必须按 Ctrl + Shift + Enter 提交上述公式。
答案 2 :(得分:0)