Question

I want to extract the last folder from a folder path:

path = C:\Users\z204685\tecware\RESULTS\D1369_3 (R=0) Surface Failure

I want to extract the last part, after the "\", in a new string:

newString = "D1369_3 (R=0) Surface Failure"

Maybe reversing the path string, then using the Split function with "\" and then reversing it again...Any better ideas?

Was it helpful?

Solution

Here's my stab at it:

Sub test()
    Dim testString As String
    Dim test As Long
    Dim output As String

    testString = "C:\Users\z204685\tecware\RESULTS\D1369_3 (R=0) Surface Failure"

    test = InStrRev(testString, "\")

    output = Right(testString, Len(testString) - test)

End Sub

Hope it gets you close!

OTHER TIPS

Look up the InStrRev function.

Another solution, according to @TimWilliams comment, You can achieve this using Split and UBound

Sub test()

Dim fpath As String
Dim newString As String
Dim temp_arr As Variant

fpath = "C:\Users\z204685\tecware\RESULTS\D1369_3 (R=0) Surface Failure"
temp_arr = Split(fpath, "\")
newString = temp_arr(UBound(temp_arr))

End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top