我正在尝试进行反向查找。
有:句子(字符串) 寻找:关键字(数组)
我知道我可以用 if(iser(find("Missing",B1,1)),if(isrr(find("Located",B1,1)),.. 做一个相当疯狂的复合语句。
但是考虑到我需要使用这个 1000 次,并且 if then's 将是 18 深。那是没有意义的。我知道我可以很清楚地用 VBA 做到这一点,但我似乎无法弄清楚语法。
这是我到目前为止所拥有的:
Function FindValue(ByRef strToSearch As String, rngLookUpValues As Range) As String
On Err GoTo err_capture
'strToSearch is the sentence I am searching
'rngLookUpValue is a two column Range.
' The first column is what I'm searching for. If it exists in the sentence,
' return the second column
' The second column is the category that applies when the word from column one
' is found in the sentence
i = 0
For Each row In rngLookUpValues
i = i + 1
If InStr(1, strToSearch, row.cell(i, 1).Value, vbTextCompare) > 0 Then
FindValue = row.cell(i, 2).Value
End If
Next
Exit Function
err_capture:
Debug.Print Err.Number & ": " & Err.Description
End Function
当我运行它时,它返回一个#Value。但是当我调试它或观察它运行时,没有错误。它只是在 instr() 函数期间死亡。