根据单元格中的多个字符串,Excel 输出值
Dim pos As Integer pos = InStr("find the comma, in the string", ",")
将返回pos为15
如果没有找到,它将返回0
如果你需要用Excel公式找到逗号,可以使用=FIND(",";A1)
函数。
请注意,如果你想使用Instr
不区分大小写地查找字符串的位置,请使用Instr的第三个参数,并给它常数vbTextCompare
(或者只是1)。
Dim posOf_A As Integer posOf_A = InStr(1, "find the comma, in the string", "A", vbTextCompare)
将给你一个值14。
请注意,在这种情况下,你必须像我链接的规范所述指定起始位置:如果指定了比较,则需要起始参数。