想要从索引数组中获取多个值到excel中的单个单元格中

时间:2016-06-08 08:05:35

标签: excel excel-formula

我正在尝试找到一种方法从数组中获取多个值以在一个单元格中显示

比如说我有两列如下

1

b 2

c 1

d 3

e 2

我希望所有值都形成第一列,其中第二列是1

vlookup和带匹配的索引都只提供第一个匹配的实例,有没有办法用函数执行此操作,还是必须在带有VBA的宏中创建?

由于

3 个答案:

答案 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)

enter image description here

答案 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 提交上述公式。

enter image description here

答案 2 :(得分:0)

使用辅助列可以单独使用公式。

enter image description here

公式:

onPostExecute

D1

="" 向下:

D2

=IF(B2=$B$1,D1&A2&", ",D1)

C1