我试图做一个向后VLOOKUP。如何检查一个值,看看它是否包含18个值
有:句子(字符串) 寻找:关键词(阵列)
我知道我可以做一个比较疯狂的复合语句 IF(ISERR(找到( “失踪”,B1,1)),如果(iserr(find(“Located”,B1,1)),..
但是考虑到我需要使用这1000次,如果那么就是18深,那只是没有意义。 我知道我可以用VBA做到这一点相当clealy,但我似乎无法找出语法
这里是我到目前为止:
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()函数中死掉。
让我们明确一点:你在EXCEL调用FindValue,所以FindValue是UDF。 您呼叫FindValue像“= FindValue(‘失踪’,B1:C5)” 要匹配“失踪”对B1:B5,并返回该行的C列的值。 --->你应该使用VLOOKUP 或者你通过 = FindValue(“一些值范围相匹配”,“一定范围内的值来匹配”) – Larry