Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何使用VBA在字符串中查找字符_Excel_Vba_Worksheet Function - Fatal编程技术网

Excel 如何使用VBA在字符串中查找字符

Excel 如何使用VBA在字符串中查找字符,excel,vba,worksheet-function,Excel,Vba,Worksheet Function,我已经从另一个功能中通过了,foldername,如foldername=“a\\b\\c”或foldername=“a”,我试图找到文件夹名包含“\\\”,并用“\\\”替换,基于“\\\\\/code>拆分foldername并传递到一个数组中 请看一看我一直在尝试什么 样本值: If WorksheetFunction.Find("\\", foldername) = 1 Then foldername = WorksheetFunction.Substitute(fold

我已经从另一个功能中通过了,foldername,如
foldername=“a\\b\\c”
foldername=“a”
,我试图找到文件夹名包含
“\\\”
,并用
“\\\”
替换
,基于
“\\\\\/code>拆分foldername并传递到一个数组中

请看一看我一直在尝试什么

样本值:

If WorksheetFunction.Find("\\", foldername) = 1 Then
       foldername  = WorksheetFunction.Substitute(foldername, "\\", "__")
       SheetNames() = Split(foldername, "__")
End If
我得到下面的错误

这样就可以了。

将a设置为整数
Dim a as Integer

'consider current value of is `foldername  = "a\\b\\c"`

a = InStr(foldername, "\\")

'if InStr is not able to find the value funtion returns 0

If a <> 0  Then
       foldername  = Replace(foldername, "\\", "__")
       SheetNames() = Split(foldername, "__")
End If
'考虑的当前值为'foldername=“a\\b\\c”` a=InStr(文件夹名称“\\”) '如果InStr找不到值,函数返回0 如果是0,那么 foldername=Replace(foldername,“\\”,“\\”) SheetNames()=拆分(foldername,“\”) 如果结束

谢谢你们的建议,伙计们,谢谢

INSTR
是在字符串中检查字符串的方法。但是你能理解你想要达到的目标吗?您可以在VBA中使用
REPLACE
,或
foldername=Join(Split(foldername,\\”,“\\”)
use INSTR(foldername,\\”),这将返回一个数字,因此您是否建议相应地更改if条件?最后一次编辑,您的问题已加入“不清楚您在问什么”类别。请使用“原始加入”和“返回”以及“为什么要使用此方法而不是使用内置函数?”?替换(foldername、“\\”、“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu。
Dim a as Integer

'consider current value of is `foldername  = "a\\b\\c"`

a = InStr(foldername, "\\")

'if InStr is not able to find the value funtion returns 0

If a <> 0  Then
       foldername  = Replace(foldername, "\\", "__")
       SheetNames() = Split(foldername, "__")
End If