本文介绍了VBA,TRIM部分路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我说我有一个路径:stack / overflow / question / help / please。 最终结果是:help / please。有没有人有一个代码,我可以在这里说明我要解析的/数量。
它类似于文本列,但我想保留在一个单元格。
谢谢
解决方案
你可以写一个这样的函数:
函数RightPart(s As String,d As String,n As Long)As String Dim A As Variant Dim i As Long,ub As Long Dim t As String A = Split(s,d) ub = UBound(A)如果n> = ub然后 RightPart = s 退出函数 End If 对于i = ub - n + 1 To ub t = t& A(i)& IIf(i ub,d,)下一个i RightPart = t 结束函数然后 RightPart(:stack / overflow / question / help / please,/,2)评估为help / please
Lets say I have a path : stack/overflow/question/help/please . And end result is : help/please.
Does anyone have a code where I can state how many "/" I want to parse.
its similar to text to columns but I would like to keep it in one cell.
Thanks
解决方案You could write a function something like this:
Function RightPart(s As String, d As String, n As Long) As String Dim A As Variant Dim i As Long, ub As Long Dim t As String A = Split(s, d) ub = UBound(A) If n >= ub Then RightPart = s Exit Function End If For i = ub - n + 1 To ub t = t & A(i) & IIf(i < ub, d, "") Next i RightPart = t End FunctionThen RightPart(":stack/overflow/question/help/please","/",2) evaluates to "help/please"
更多推荐
VBA,TRIM部分路径
发布评论