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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
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

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,961
Office Version
  1. 365
Platform
  1. Windows
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

Ragnar1211

Well-known Member
Joined
Jul 10, 2008
Messages
571
= mid(filename,len("Statusreport")+1,len(filename)

change filename to however you are obtaining the filename.
 
Upvote 0

metropol

Board Regular
Joined
Aug 19, 2005
Messages
209
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

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,961
Office Version
  1. 365
Platform
  1. Windows
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

metropol

Board Regular
Joined
Aug 19, 2005
Messages
209
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

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
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,191,215
Messages
5,985,314
Members
439,956
Latest member
venky2002

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
Top