【发布时间】:2014-05-12 22:25:23
【问题描述】:
好的,我写了一个 UDF,它在给定的单元格中搜索特定的子字符串。 如果在单元格中找到子字符串,则返回 TRUE,如果未找到,则返回 FALSE。
这是 UDF 的代码(命名为 contains 函数)
Function contains(substring As String, testString As String) As String
'testString = cell to be tested for substring
Dim result As Boolean
result = False
testString = UCase(testString)
substring = UCase(substring)
For i = 1 To Len(testString)
If Mid(testString, i, Len(substring)) = substring Then result = True
Next
contains = result
End Function
我创建这个函数的原因是我可以将它嵌套在常用的 Excel 函数中,主要是 IF 函数、AND functionS 和 OR 函数。
但是,当我将它与 OR 函数一起使用时,OR 函数似乎无法“识别” =contains 函数的结果。
这是 Excel 中问题的屏幕截图:
编辑这是上面图片中 =contains 函数的作用=contains("Hello",A2)
显然,由于 C 列中的 =Contains 函数返回 True,因此 D 列中的 OR 函数也应该返回 True。但由于某种原因,就好像股票 Excel OR 函数无法识别我的 contains 函数的结果。
【问题讨论】:
标签: vba excel boolean excel-2007