Help parsing a string

KGee

Well-known Member
Joined
Nov 26, 2008
Messages
537
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a folder path saved as a variable and want to keep the part after the \ which follows folder 2. Is there a way to count the number of "\'s" in the string and give me everything that follows after the sixth occurrence of the slash? I want to repeat this code in different areas and the folder names vary as well as the length so I can't specify a starting character position.

Original string:
Code:
\\server\share\folder1\folder2\folder3\folder4\folder5\
Desired output:
Code:
folder3\folder4\folder5\
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
In VBA you can also use a loop to get the desired string:
Code:
For i = 1 To 6
    MyString = Mid(MyString, InStr(1, MyString, "\") + 1, Len(MyString))
Next i
 
Upvote 0
In VBA you can also use a loop to get the desired string:
Code:
For i = 1 To 6
    MyString = Mid(MyString, InStr(1, MyString, "\") + 1, Len(MyString))
Next i
I was just going to ask if there was a VBA equivalent for substitute as I need to do this in VBA. Both of the formula options posted also work.

Thanks!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,393
Members
449,446
Latest member
CodeCybear

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top