Pull string from filename

diimoo1

New Member
Joined
Jun 12, 2011
Messages
34
Looking help - a way to pull the string from the filename and perform a task using the string part of the formula manually. Right now I can pull the file from the folder and use the string part of my program

C:\ XXXX_555_GGGGG.xlsx ( extraxt '555")

C:\ XXXX_101_GGGGG.xlsx (extraxt"101")

....cont!

manually we can do this for each of the files:

Code:
{ Sub Combined() wb.Sheets("Sheet1").Range("b2").Value = Application.SumIfs(Sheet1.Columns(2), Sheet1.Columns(1), "555") End Sub

Sub Combined1() wb.Sheets("Sheet1").Range("b3").Value = Application.SumIfs(Sheet1.Columns(2), Sheet1.Columns(1), "101")

End Sub

Looking for a better way to automated this:

Open the folder

pull the string from filename path ( file one) ( i.e '555')

use the string part of my sum formula

next file

Thanks in advance
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try this method
VBA Code:
Sub test()
    Dim x
    x = "C:\ XXXX_555_GGGGG.xlsx "
    Debug.Print Split(Split(x, "\")(UBound(Split(x, "\"))), "_")(1)
End Sub
 
Upvote 0
Solution
I see that you already have a good working solution but FWIW here is an alternative that requires a bit less calculation/manipulation.

Rich (BB code):
Debug.Print Split(Split(x, "\")(UBound(Split(x, "\"))), "_")(1)
Debug.Print Split(Mid(x, InStrRev(x, "\")), "_")(1)
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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