Get only file name from file location string.

Newbie212

New Member
Joined
Oct 15, 2018
Messages
16
Office Version
  1. 2010
Platform
  1. Windows
Hello i made a macro that uploads files, using FileToOpen in vba that Browses for your File and Imports Range in a cell with output that looks something like this:
VBA Code:
C:\Users\User\Desktop\Example Folder Name\Test.pdf

My question is there a formula or some other way to get only the file name, or in other words - Test.pdf in the above example, displayed in the cell(or some other "display only" cell)? This must not change the value of the cell because i need the whole file location string to upload the file.

Im sorry if its trivial question, thanks in advance.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Like this?

21 10 21.xlsm
AB
1C:\Users\User\Desktop\Example Folder Name\Test.pdfTest.pdf
FName
Cell Formulas
RangeFormula
B1B1=TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",100)),100))
 
Upvote 0
Solution
I suggest that you update your Account details
Done.

Thank you very much, Peter. Woks like a charm and as bonus took us like 10 minutes of experimenting and discussing with colleagues what the formula does exactly and how does it work, witch was good fun.

Once again. Thank you and have a nice day. :)
 
Upvote 0
You're welcome. Thanks for the follow-up. (Also glad to give you and your colleagues some brain exercise. :biggrin:)

Thanks for updating your profile. (y)
 
Upvote 0
BTW, I forgot to mention that you could also do this quickly manually ..

1. Copy/Paste the whole column to a blank column
2. Do a Find/Replace on that new column with these settings:

1634808780650.png
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

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