excel - Instr 函数未找到子字符串

标签 excel function vba

我有以下 VBA 代码,它为 InStr 函数返回“0”:

If InStr("ICD-10 & CPT OPC NHSN", "JCMC ICD-10 & CPT OPC NHSN Sep-17 new.xlsx") > 0 Then
   'Do something
End If

但是,以下代码使用 WorksheetFunction.Find 函数将子字符串定位在位置 6:
If Application.WorksheetFunction.Find("ICD-10 & CPT OPC NHSN", "JCMC ICD-10 & CPT OPC NHSN Sep-17 new.xlsx") > 0 Then
    'Do something
End If

为什么 InStr 函数未找到子字符串时 WorksheetFunction 返回 6?

最佳答案

如果你看the documentation for the InStr function您会看到两个强制参数中的第一个是要搜索的字符串,第二个参数是要查找的字符串。

string1 Required. String expression being searched.
string2 Required. String expression sought.



所以你的代码需要
If InStr("JCMC ICD-10 & CPT OPC NHSN Sep-17 new.xlsx", "ICD-10 & CPT OPC NHSN") > 0 Then
   'Do something
End If

关于excel - Instr 函数未找到子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47640083/

相关文章:

具有大数据的 PhpSpreadsheet

function - 非空函数不返回任何 Dart

perl - 在 Perl 中,如何将函数作为另一个函数的参数传递?

java - 从 VBA 代码启动 jar 文件

Python:如何根据 if 语句的结果将元素输出到特定的列和行

Excel 查找列中的下一个值

Excel Power Query/M - 根据网站上可用的页数动态组合连接数

javascript - 在 JavaScript 函数中定义全局变量

excel - VB : Filtering data on excel table

html - MSXML2.XMLHTTP 能否检索给定网页的所有 HTML 数据?