SPLIT FUNCTION IN VBA

CLINT WILLIAMS

Board Regular
Joined
Nov 8, 2011
Messages
69
Office Version
  1. 365
Good afternoon All

I am hoping that someone can help me please, I am using the split function as below to split the file name with "." which works fine but filename has now changed to : Filename = "Bulk(011)_1021.xlsx" that includes an underscore. How would I alter the MySplit part of the code to include the "_". Any help would be appreciated.

Filename = "Bulk(011).1021.xlsx"
MySplit = Split(Filename, ".", -1)
Mynewfilename = MySplit(0) & "." & SF_YYYY & "." & MySplit(2)
Workbooks.Open Filename:=Path & Mynewfilename, UpdateLinks:=False
MyBook2 = ActiveWorkbook.Name

Thanks
Clint
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
What is your desired result?
And what is the value of SF_YYYY, which appears to be some sort of variable (though you do not show the value in the code you posted)?
 
Upvote 0
How about
VBA Code:
Filename = "Bulk(011)_1021.xlsx"
MySplit = Split(Filename, "_")
Mynewfilename = MySplit(0) & "_" & SF_YYYY & "." & Split(MySplit(1), ".")(1)
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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