Extract file name from formula

Kevinax

New Member
Joined
Mar 29, 2010
Messages
25
I have a formula linking to a separate file. I need to extract the file name as text. For example: formula says
=+'W:\test budget\[East.xlsx]2015 Budget'!$B$1
In the cell below I need 'East.xlsx
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I have a formula linking to a separate file. I need to extract the file name as text. For example: formula says
=+'W:\test budget\[East.xlsx]2015 Budget'!$B$1
In the cell below I need 'East.xlsx

Try...
Rich (BB code):
=REPLACE(LEFT(CELL("filename",A1),FIND("]",CELL("filename",A1))-1),1,
  FIND("[",CELL("filename",A1)),"")
 
Upvote 0
You could try this user-defined function. To implement ..

1. Right click the sheet name tab and choose "View Code".

2. In the Visual Basic window use the menu to Insert|Module

3. Copy and Paste the code below into the main right hand pane that opens at step 2.

4. Close the Visual Basic window.

5. Enter the formula as shown in the screen shot below and copy down.

6. If using Excel 2007 or later your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

Code:
Function Fname(r As Range) As String
  Fname = Split(Replace(r.Formula, "[", "]"), "]")(1)
End Function

Excel Workbook
C
1#REF!
2East.xlsx
Extract file name
 
Upvote 0
Thanks for the reply but I'm entirely uncomfortable with visual basic.
 
Last edited:
Upvote 0
Try...
Rich (BB code):
=REPLACE(LEFT(CELL("filename",A1),FIND("]",CELL("filename",A1))-1),1,
  FIND("[",CELL("filename",A1)),"")

Thanks for the reply but the formula seems to be giving me the file name of the current file and not the file name referenced in the formula.
 
Upvote 0
For added clarification ....... I'm working in a file named Summary.xlsm, this file has the following formula: =+'W:\test budget\[East.xlsx]2015 Budget'!$B$1 I need a formula in the Summary file that returns East.xslm not Summary.xlsm
 
Upvote 0
I copied the formula as text to B1 and used the MID function in C1. In Excel 2013, you can use the FPRMULATEXT function for cell B1


Excel 2010
ABC
1#REF!+'W:\test budget\[East.xlsx]2015 Budget'!$B$1East.xlsx
Sheet3
Cell Formulas
RangeFormula
A1=+'W:\test budget\[East.xlsx]2015 Budget'!$B$1
C1=MID(B1,FIND("[",B1)+1,FIND("]",B1)-FIND("[",B1)-1)
 
Upvote 0
This works, thank you. Is there any way to extract East.xlsx directly from cell A1 rather than as a 2 step process(e.g. avoiding cell B2)?
 
Upvote 0
This works, thank you. Is there any way to extract East.xlsx directly from cell A1 rather than as a 2 step process(e.g. avoiding cell B2)?

Why don't you enter in A1
Rich (BB code):
=REPLACE(LEFT(CELL("filename",A1),FIND("]",CELL("filename",A1))-1),1,
  FIND("[",CELL("filename",A1)),"")
as suggested?
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

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