如何在Excel“表格”中搜索值?

时间:2019-05-09 19:30:25

标签: excel excel-formula vlookup libreoffice-calc

例如,如果我有此表:

a,6,10,22,35,46
b,2,7,11,23,44,78
c,2,10,15,16,32,66,98
d,7,8,10,11,23,25,30
e,23,24

现在,我想搜索某个值的出现次数,并返回每个对应行的第一列的值。

因此2给出:b,c。并且23给出b,d,e

赞:

2,b,c
23,b,d,e

是否可以通过使用VLOOPUP-或其他功能来实现?

谢谢!

2 个答案:

答案 0 :(得分:1)

如果您愿意使用解决方案,则可以创建自己的函数:

只需确保将其插入新模块

Option Explicit

Public Function INCOLUMNS(ByVal value As String, ByVal searchrange As Range) As String

    Dim res As String
    Dim i As Long
    Dim temp As Range

    For i = 1 To searchrange.Columns.Count
        Set temp = Range(Cells(1, i), Cells(searchrange.Rows.Count, i)). _ 
                   Find(value, LookIn:=xlValues, LookAt:=xlWhole)
        If Not temp Is Nothing Then
            If res = "" Then
                res = Split(Cells(1, i).Address, "$")(1)
            Else
                res = res & ", " & Split(Cells(1, i).Address, "$")(1)
            End If
        End If
    Next i

    INCOLUMNS = res
End Function

然后您可以在Worksheet内部使用它,如下所示:

enter image description here

答案 1 :(得分:0)

如果我正确地理解了该问题,并且该列与,一致并且没有空格,那么我编写的公式如下:

=IF(ISNUMBER(SEARCH(",23,",A1)),"23,b,d,e",IF(ISNUMBER(SEARCH(",2,",A1)),"2,b,c","N/A"))

假设a,6,10,22,35,46A1中,则可以将其粘贴在B1中,然后将公式向下拖动。这样可以为您的示例提供所需的结果。

回答这个公式:

Results

关于IF(ISNUMBER(SEARCH公式的文档:https://exceljet.net/formula/if-cell-contains

希望这会有所帮助,

-Maykid