The best thing about Excel is that you can do the same thing in several ways. Our yesterdays problem – Extracting file name from full path is no different. There are many different ways to do it, apart from writing a formula. Learn these techniques to be a data extraction ninja.
1. Using Find Replace
Suggested by Iain in the comments yesterday, I love this technique for its simplicity and awesomeness.
- Select all the file paths
- Press CTRL+H
- Type *\ in find field
- Leave the replace field empty.
- Click on Replace all.
- Done!
It is that simple. Do not believe me? See this demo.

Thanks Iain for teaching us this trick.
2. Using Text to columns utility
Buried inside heap of features in Excel is this beautiful Text to columns utility, that can take any text and convert it in to many columns based on the delimiter you specify. [more uses of text to columns]
This is how we can use it:
- Select all the file path cells
- Go to Data > Text to columns
- Chose “Delimited” in step 1 and click next.
- Specify delimiter as \

- Click Finish
- You will get all folders in to separate cells and file name in last cell.
- Now use a formula like =INDEX($C3:$O3,COUNTA($C3:$O3)) to extract the last cell’s value ie file name
- Done!

3. Using UDFs
While our formula method tends to be very long or very complicated, we can use 1-2 line VBA to get the file name from a full path. There are many ways to skin this cat in VBA, but 2 easiest methods are,
For both methods below, you first need to insert a new module and add the code in that.
Using InStrRev
As suggested by Daniel Ferry in the comments.
Public Function ParseFile(sPath As String) As Variant
ParseFile = Array(Mid$(sPath, 1 + InStrRev(sPath, “\”)), Mid$(sPath, 1 + InStrRev(sPath, “.”)))
End Function
Note: this UDF returns an array for file name & extension. So you need to enter it in 2 cells together.
The InStrRev() built in function searches for \ in the sPath from end and returns the first occurrence’s position.
Using split
As suggested by PPH in comments,
Function ExtractFileName(filepath) As String
Dim x As Variant
x = Split(filepath, Application.PathSeparator)
ExtractFileName = x(UBound(x))
End Function
What is your favorite method?
For most of my data cleaning needs, I use a mix of text to columns, find-replace or VBA. In rare cases, I rely on a formula. This is because data cleaning or extraction is usually one time step and figuring out a complex formula is not good idea in such cases.
What about you? How do you go about extracting filenames, dates, numbers etc. buried in text? What method do you use often? Please share with us in comments.
















6 Responses to “Nest Egg Calculator using Power BI”
Wow! What a Powerful article!
Hello Chandoo Sir
your file does not work with Excel 2016.
how can I try my hands on this powerful nest egg file ?
thanks
Ravi Santwani
@Ravi... this is a Power BI workbook. You need Power BI Desktop to view it. See the below tutorial to understand what Power BI is:
https://chandoo.org/wp/introduction-to-power-bi/
As always, superb article Chandoo... 🙂
Just one minor issue:
While following your steps and replicating this calculator in PowerBI, I found that the Growth Pct Parameters should be set as "Decimal number" not "Whole Number"
OR
we have to make corresponding adjustments in the Forecast formulas (i.e. divide by 100) to get accurate results.
You are right. I used whole number but modified the auto created harvester measure with /100 at end. Sorry I did not mention it in the tutorial.
Instead of
[Growth Pct 1 Value]/12
the monthly rate has to be
(1+[Growth Pct 1 Value])^(1/12)-1
It's a slight difference but in 30 years the future value will be $100k less.