Inserting a filename in a cell and resizing

chadski778

Active Member
Joined
Mar 14, 2010
Messages
297
I would like to insert a filename into a cell (A6). Unfortunately, the filename contains a string that I do not require. It consists of a product name (required), space, formulation code, space, date. Could I have code for inserting a filename in A6 and then removing the last 20 characters, including spaces, from the right side of the filename. A typical filename would be 'shell helix 140001983331 10Aug11'. I just want 'shell helix'

Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Working here

Code:
Sub test()
Dim fName As String
fName = "shell helix 140001983331 10Aug11"
Range("A6").Value = Left(fName, Len(fName) - 20)
End Sub
 
Upvote 0
The filename i gave was just an example. I want it to work automatically with different filenames that are in a similar format to the one i provided
 
Upvote 0
It works if I use

Range("A6").Value = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 20)

Thanks for your help
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

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