Formula to extract file name not working correctly

sparky2205

Active Member
Joined
Feb 6, 2013
Messages
481
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi folks,
I have the following formula in a template:
Excel Formula:
=MID(@CELL("filename"),SEARCH("[",@CELL("filename"))+1, SEARCH("(",@CELL("filename"))-SEARCH("[",@CELL("filename"))-2)
Each time the template is used it is given a sequential number by the system.
I download two of these documents to a network folder, which are now called, let's say, File1 and File2.
I open the two documents in the order File1, File2.
Now they both have the document number File2 in the field where the formula is.
If I open them in the order File2, File1 they both have the number File1 where the formula is.
i.e. whichever document is opened last both documents will take that document number.
It doesn't matter how many documents you have open all documents will take the number of the last document opened.
I feel like I'm missing something simple but I don't know what.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Dont't use CELL("filename") but
Excel Formula:
CELL("filename",A1)
 
Upvote 0
Solution
Thanks Anthony,
that works. Could you explain that logic to me please?
What does using A1 as the [reference] actually do?
And why does it not work without it?
 
Upvote 0
Your formula did not work for me.
The following will yield the file name.
You may have to make the formula volatile.

Cell Formulas
RangeFormula
A3A3=LET(FileN,CELL("filename",A1),REPLACE(LEFT(FileN,FIND(".",FileN)-1),1,FIND("[",FileN),""))
A4A4=IF(NOW()>N1,CELL("filename",A1),"")
 
Upvote 0
Thanks Anthony,
that works. Could you explain that logic to me please?
What does using A1 as the [reference] actually do?
And why does it not work without it?
Without a reference the function will return a value based on the current active cell
See CELL function
 
Upvote 0
I'm not sure why it doesn't work for you Anthony, but it does work for me.
Thanks very much for the pointer to the CELL function description.
It now makes perfect sense.

Thanks for your help.
 
Upvote 0
T202207b.xlsm
A
2#VALUE!
3T202207b
1a
Cell Formulas
RangeFormula
A2A2=MID(CELL("filename"),SEARCH("[",CELL("filename")+1), SEARCH("(",CELL("filename"))-SEARCH("[",CELL("filename"))-2)
A3A3=LET(FileN,CELL("filename",A1),REPLACE(LEFT(FileN,FIND(".",FileN)-1),1,FIND("[",FileN),""))
 
Upvote 0

sparky2205 or​

Anthony47

Did either of you actually try the formula that

sparky2205 posted?​

I showed with my post that it gives a Value error. Did the post not show the complete formula?

Could you post with XL2BB an example where it works?
 
Upvote 0

Forum statistics

Threads
1,215,509
Messages
6,125,216
Members
449,215
Latest member
texmansru47

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