Or you can try:
Sub sTest1() Dim nPath1 As Variant, st As String st = "Root\zTrash - No longer needed\NOC\NOC" nPath1 = Split(st, "\") ReDim Preserve nPath1(UBound(nPath1) - 1) st = Join(nPath1, "\") Debug.Print st End Sub
This is useful if you want to delete more than one element (not only the last) by changing 1 to 2 or 3, for example:
Sub sTest2() Dim nPath1 As Variant, st As String, n As Long st = "Root\zTrash - No longer needed\NOC\NOC" For n = 1 To 3 nPath1 = Split(st, "\") ReDim Preserve nPath1(UBound(nPath1) - n) Debug.Print Join(nPath1, "\") Next
Results:
Root\zTrash - No longer needed\NOC Root\zTrash - No longer needed Root
source share