子串匹配

时间:2018-10-09 20:44:20

标签: string vba user-defined-functions

尝试进行简单的子字符串vba匹配时遇到很多麻烦。我正在尝试创建一个将单词库与单个单元格匹配且不区分大小写的函数。

这是我的代码

Function Simplematch(Rng As Range, Bank As Range) As String

Application.Volatile
Dim result1 As String
Dim singlecell As Range

For Each singlecell In Bank

  If InStr(LCase(singlecell), LCase(Rng)) <> 0 Then
  result1 = InStr(LCase(singlecell), LCase(Rng))
  End If

'exit loop if there is a match
    If result1 > 0 Then Exit For

'continue looping    
Next singlecell

simplematch= result1

End Function

所需结果 Result

0 个答案:

没有答案