Formula Help Needed

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


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:

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 |.
Rob HensonFinance AnalystCommented:
This is shorter:


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


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

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

NorieAnalyst Assistant Commented:
Try this formula.

Sonia BowditchInformation Security OfficerAuthor Commented:

Both solutions are very helpful.
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.
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.
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.