Split string variable and use some in filename

metropol

Board Regular
Joined
Aug 19, 2005
Messages
209
I have a filname called ex: "Statusreport xxyyzz.xls"

I'm only interested to put xxyyzz in a variable and reuse it for saving another workbook.

How can I use the different string functions for this. The word "Statusreport" is used for apporx 20 different workbooks.

Sorry for asking, but I have never worked with string variables before.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You can use a formula to get the file name, then just refer to the range it's in:

=RIGHT(A1,LEN(A1)-FIND(" ",A1))

HTH,
 
Upvote 0
Since your leading text is always the same:

You just need the text starting at the 14th position:

Code:
Sub test()
Dim fn As String
fn = "Statusreport xxyyzz.xls"
MsgBox Mid(fn, 14)
End Sub
 
Upvote 0
= mid(filename,len("Statusreport")+1,len(filename)

change filename to however you are obtaining the filename.
 
Upvote 0
I gave you some VBA code, does it do what you need?


Maybe I don't understand this. When you use '=right ' and FIND statement, it seems to me that this is a formula you put in the excel sheet.
I'm running a macro vba code, and looking for string functions in the vba code.

I tried your code in the macro, but it did not recognize the FIND statement.
 
Upvote 0
That is not what I posted:

Code:
Sub test()
Dim fn As String
fn = "Statusreport xxyyzz.xls"
MsgBox Mid(fn, 14)
End Sub
 
Upvote 0
That is not what I posted:

Code:
Sub test()
Dim fn As String
fn = "Statusreport xxyyzz.xls"
MsgBox Mid(fn, 14)
End Sub

So sorry Hot pepper. Didn't see your code at first.

The code you provided was a good shot. Still I have the .xls ending with is not neede Ex xxxyyyzz.xls only xxxyyyzz.
 
Upvote 0
Maybe I don't understand this. When you use '=right ' and FIND statement, it seems to me that this is a formula you put in the excel sheet.
I'm running a macro vba code, and looking for string functions in the vba code.

I tried your code in the macro, but it did not recognize the FIND statement.

I posted a formula. In your code you would then reference the cell housing the formula.

But what Scott posted works without the need for a formula.
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,027
Members
448,543
Latest member
MartinLarkin

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