本文介绍了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 Function

Then RightPart(":stack/overflow/question/help/please","/",2) evaluates to "help/please"

这篇关于VBA,TRIM部分路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 16:31