BenefitRich
New Member
Greetings all!
I have a bunch of cells that are lists of filenames that all follow the same format:
[pre]
Where I use the Mid function and find the first "_" with a Search, then add 1 to that position and embed that in another Search, but this time it will start right after the 1st "_" and so it will give me the 2nd "_". To get the # of spaces for the MID to go over, I then subtract the position of the 2nd "_" from the position of the 3rd "_" which I get using the same recursive search route.
Can you think of a better way?
Thanks in advance!
I have a bunch of cells that are lists of filenames that all follow the same format:
[pre]
Code:
DFC_000094_AUST_bill.xls
DFC_000095_BRAZ_bill.xls
DFC_000096_CANA_bill.xls
DFC_000097_CHIL_bill.xls[/pre]
I need to extract the four letter code that is in between the 2nd and 3rd "_" for each. AUST, BRAZ, CANA, CHIL
Right now, the best way I have to do this is as follows, but I have to imagine there's a better way: [Assuming the filename is in cell A1]:
=MID(A1,(SEARCH("_",A1,(SEARCH("_",A1)+1))+1),((SEARCH("_",A1,(SEARCH("_",A1,(SEARCH("_",A1)+1))+1)))-(SEARCH("_",A1,(SEARCH("_",A1)+1))+1)))
Where I use the Mid function and find the first "_" with a Search, then add 1 to that position and embed that in another Search, but this time it will start right after the 1st "_" and so it will give me the 2nd "_". To get the # of spaces for the MID to go over, I then subtract the position of the 2nd "_" from the position of the 3rd "_" which I get using the same recursive search route.
Can you think of a better way?
Thanks in advance!