VBA,倒数第二名“/&引用;使用InstrRev

VBA,倒数第二名“/&引用;使用InstrRev,vba,excel,Vba,Excel,我有解析字符串最后一个单词的代码。 也就是说,叠加/叠加/流动将给我“流动” 但我想“过/流” 这是我得到的,但只能得到“流动” arr(counter-2)=“'”和mid(Text,InStrRev(Text,“/”+1)和“'”最初误读了问题。您可以嵌套instrev()调用 arr(counter - 2) = "'" & mid(Text, InStrRev(Text, "/",InStrRev(Text, "/")-1)+1) & "'" 我会使用Split()

我有解析字符串最后一个单词的代码。 也就是说,叠加/叠加/流动将给我“流动”

但我想“过/流”

这是我得到的,但只能得到“流动”


arr(counter-2)=“'”和mid(Text,InStrRev(Text,“/”+1)和“'”
最初误读了问题。您可以嵌套
instrev()
调用

arr(counter - 2) = "'" & mid(Text, InStrRev(Text, "/",InStrRev(Text, "/")-1)+1) & "'"
我会使用
Split()


下面是一个函数:

Function lastParts(str As String, delim As String, x As Long) As String
Dim splt() As String
splt = Split(str, "/")

If UBound(splt) + 1 >= x Then
   Dim t As String
   t = "=INDEX(INDEX({""" & Join(splt, """;""") & """},N(IF({1},ROW(" & UBound(splt) - x + 2 & ":" & UBound(splt) + 1 & "))),),)"
   lastParts = Join(Application.Transpose(Application.Evaluate(t)), delim)
Else
    lastParts = str
End If
End Function
它有三个部分:字符串、分隔符和返回数

可以使用您的代码调用它:

arr(counter-2) = lastParts(Text,"/",2)
或从工作表中选择

=lastParts(A1,"/",2)

我个人不会使用split,因为它只适用于包含2个斜杠的值(除非还包含循环,这在我看来是不必要的)。。。这取决于你想要它做什么,我不明白。你自己的答案只适用于两个,op说,两个,我在哪里看到了更多或更少。我完全误解了你的答案。xD今天表现不好似乎。。。XD谢谢Scott,请不要因为我使用了Sancam答案而生气。@excelguy无意冒犯,你选择了最适合你的答案。
=lastParts(A1,"/",2)