parse file name

DHolcombe

Board Regular
Joined
Mar 4, 2007
Messages
100
Office Version
  1. 2016
Platform
  1. Windows
Hi, I have a situation and not sure the best most efficient way to parse a file name. I have a directory of files i need to process and i need to collect information from each file name before i process each file.

Below are two examples of file names:
sec_abcdef_lg6789_david_ted
ext_jurtyu_pmd998_9259_wendy H_ted


The file names have the following naming convention:
Each file name contains the follow information:
section_part_loginfo_name_ted

section and part are the first two pieces of information
name and ted are the last two pieces of information
loginfo is after the "part" but before the "name"

for the examples above:
loginfo: lg6789
loginfo: pms998_9259


Note: i would have posted a file but i was not sure how to post a file.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
What version of Excel are you using? Can you update your profile with that information?

Also, can you show what output/result you are hoping for?
 
Last edited:
Upvote 0
i am using microsoft office home and student 2016 (at home) and Microsoft 365 at work

Output is to parse file name into the respective pieces. So for each file name there were be
section_txt = "sec"
part_txt = "abcdef"
loginfo_txt = "lg6789"
name_txt = "david"
ted_txt = "ted"
 
Upvote 0
i am using microsoft office home and student 2016 (at home) and Microsoft 365 at work
Please update your account details. That way it will show in your details and you won't need to explicitly mention it in every thread/question.
Click on this link to edit your account details: Account details (and don't forget to click "Save" at the bottom).
 
Upvote 0
Maybe something like this for 365, for examples shown? If your loginfo has more than one underscore this won't work.
Book1
ABCDEFGHI
1
2sec_abcdef_lg6789_david_tedsecabcdeflg6789davidted
3ext_jurtyu_pmd998_9259_wendy H_tedextjurtyupmd998_9259wendy Hted
4
Sheet1
Cell Formulas
RangeFormula
E2:I3E2=SUBSTITUTE(TEXTSPLIT(IF(LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))=4,A2,SUBSTITUTE(A2,"_",";",3)),"_"),";","_")
Dynamic array formulas.
 
Upvote 0
Here's how to do it with just 2016 functions:

Book1
ABCDEFG
1sectionpartloginfonameted
2sec_abcdef_lg6789_david_tedsecabcdeflg6789davidted
3ext_jurtyu_pmd998_9259_wendy H_tedextjurtyupmd998_9259wendy Hted
Sheet7
Cell Formulas
RangeFormula
C2:C3C2=TRIM(LEFT(SUBSTITUTE(A2,"_",REPT(" ",99)),99))
D2:D3D2=TRIM(MID(SUBSTITUTE(A2,"_",REPT(" ",99)),100,99))
E2:E3E2=SUBSTITUTE(SUBSTITUTE(A2,C2&"_"&D2&"_",""),"_"&F2&"_"&G2,"")
F2:F3F2=TRIM(LEFT(RIGHT(SUBSTITUTE(A2,"_",REPT(" ",99)),200),99))
G2:G3G2=TRIM(RIGHT(SUBSTITUTE(A2,"_",REPT(" ",99)),99))
 
Upvote 0

Forum statistics

Threads
1,223,950
Messages
6,175,582
Members
452,653
Latest member
craigje92

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