Formula Help Needed

I have a variable length string that I need to extract only a certain part.

C:\folder\subfolder\filename.xls
C:\folder\subfolder\subfolder\subfolder\filename.xls
C:\folder\subfolder\subfolder\filename.xls
C:\folder\subfolder\subfolder\subfolder\subfolder\subfolder\subfolder\filename.xls

I only want the path and not the actual file name.  As you can see the path name is variable length.

I have tried a number of functions but can't quite seem to get want I need.

Any help would be greatly appreciated.
Sonia BowditchInformation Security OfficerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rob HensonFinance AnalystCommented:
Try this:
=LEFT(SUBSTITUTE(A3,"\","|",LEN(A3)-LEN(SUBSTITUTE(A3,"\",""))),FIND("|",SUBSTITUTE(A3,"\","|",LEN(A3)-LEN(SUBSTITUTE(A3,"\",""))))-1)

This counts the occurrence of \ by comparing length of the string after replacing the \ with blank. It then replaces the last \ with | and uses LEFT function to give everything to the left of the |.
0
Rob HensonFinance AnalystCommented:
This is shorter:

=LEFT(A3,FIND("|",SUBSTITUTE(A3,"\","|",LEN(A3)-LEN(SUBSTITUTE(A3,"\","")))))

Do you need the last \ before the filename, if not then:

=LEFT(A3,FIND("|",SUBSTITUTE(A3,"\","|",LEN(A3)-LEN(SUBSTITUTE(A3,"\",""))))-1)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
John TsioumprisSoftware & Systems EngineerCommented:
Well a bit different way
StrReverse (Left(StrReverse("C:\folder\subfolder\subfolder\subfolder\subfolder\subfolder\subfolder\filename.xls"), InStr(StrReverse("C:\folder\subfolder\subfolder\subfolder\subfolder\subfolder\subfolder\filename.xls"), "\") - 1))

Open in new window

If you put the path to a variable then it should read
StrReverse (Left(StrReverse(PathVariable, InStr(StrReverse(PathVariable), "\") - 1))

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

NorieVBA ExpertCommented:
Try this formula.

=SUBSTITUTE(A1,TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",LEN(A1))),LEN(A1))),"")
2
Sonia BowditchInformation Security OfficerAuthor Commented:
Thanks,

Both solutions are very helpful.
0
Rob HensonFinance AnalystCommented:
Thank you for the feedback, glad to help.

Not sure why you've marked John's solution as Assisted, there was no mention of VBA in your question.

I would have given credit to Norie as his solution works even when the source cell is blank whereas mine throws a #Value error.
0
Sonia BowditchInformation Security OfficerAuthor Commented:
Apologies as I did not notice Norie's response until after I had tested the solutions.

I am in the process of testing Norie's response and will contact support to have the points distributed.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.