Excel自定义公式,类似VLOOKUP的查询

Excel在使用VLOOKUP时,当检索值超过255长度的时候就会报错,没法正常检索。

官方提供的办法是通过INDEX和MATCH公式组合使用来解决。

微软官方方案

1,公式 

       =INDEX($A$5:$A$6,MATCH(TRUE,$A$5:$A$6=B5,0),0)

2,Ctrl+Shift+Enter

       {=INDEX($A$5:$A$6,MATCH(TRUE,$A$5:$A$6=B5,0),0)}

官方的方案理解有点儿着急。

 

就自己定义了一个searchText函数,效果不错,就哪来和大家分享一下。

excel自定义函数

函数内容


'''
''' 範囲中に、特定文字を探す。
'''
''' 結果がある場合、探したい文字を戻す。
''' 結果がない場合、空文字を戻す。
'''
Function searchText(r As Range, s As String) As String

searchText = ""

For Each c In r.CurrentRegion
    If c = s Then
        searchText = s
        GoTo end_ser
    End If
Next c
Set c = Nothing

end_ser:
Set c = Nothing

End Function
=searchText(A5:A6,B5)

返回值就是被检索的字符串。

未检索到就返回空字符串。

posted on 2018-10-23 21:56  匆匆而过  阅读(1088)  评论(0编辑  收藏  举报

导航