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

时间:2017-06-26 14:46:42

标签: excel vba worksheet-function

我已经从另一个功能,foldername = "a\\b\\c"foldername = "a"这样的文件传递过来了,我试图找到包含"\\"的文件夹名称并用"\\"替换"__" "__",根据If WorksheetFunction.Find("\\", foldername) = 1 Then foldername = WorksheetFunction.Substitute(foldername, "\\", "__") SheetNames() = Split(foldername, "__") End If 拆分foldername并传入数组。

请看看我到现在为止所做的事情。

样本值:

MEDIAN(IF(X3:X92 > 0,X3:X92))

我收到以下错误。

enter image description here

2 个答案:

答案 0 :(得分:0)

SheetNames() = Split(foldername, "\\")
foldername=join(sheetnames,"__")

这样就可以了。

答案 1 :(得分:0)

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

感谢您的建议,感谢您。