多个Excel SEARCH功能标准

问题描述 投票:0回答:1

我希望能够像使用SEARCH函数一样返回单元格中文本的位置编号,但是这可能有多个条件吗?

例如单元格中的文字是“Iphone 7 Sep 18 $ 20”

= SEARCH(“Sep”,F10,1)我正在寻找“Sep”而SEARCH已经返回位置10 - ok

但如果那个细胞可能是12个月中的任何一个呢?如果单元格有12个月中的任何一个,我想要返回位置编号。这可能使用SEARCH或其他功能吗?

excel-formula
1个回答
1
投票

请尝试以下用户定义的功能:

Public Function Msearch(llist As Variant, s As String) As Long
    Dim i As Long, sTemp As String

    If TypeName(llist) = "Range" Then
        sTemp = llist.Value
    Else
        sTemp = llist
    End If

    If InStr(sTemp, ",") = 0 Then
        Msearch = InStr(s, llist)
        Exit Function
    End If

    Msearch = 0

    arr = Split(sTemp, ",")
    For Each a In arr
        i = InStr(s, a)
        If i > 0 Then
            Msearch = i
            Exit Function
        End If
    Next a
End Function

它可以像SEARCH()一样使用,除了第一个参数可以是以逗号分隔的列表:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.