How to drop middle part of the string name in excel?

Nicklim

New Member
Joined
Sep 24, 2018
Messages
3
Hello, I hope to find help here. I need to drop middle part of a string in excel.
This is what I have:
OptionABCDcorrect
OptionDFTYuKlgkincorrecr
OptionGdhfjksjsbakvalidargument

This is what I need:
Optioncorrect
Optionincorrecr
Optionvalidargument

So basically, I need to drop middle part of the string.

Thank you!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hello, I hope to find help here. I need to drop middle part of a string in excel.
This is what I have:
OptionABCDcorrect
OptionDFTYuKlgkincorrecr
OptionGdhfjksjsbakvalidargument

This is what I need:
Optioncorrect
Optionincorrecr
Optionvalidargument

So basically, I need to drop middle part of the string.
You have overly generalize whatever it is that you need as your 2nd and 3rd examples are not dropping the "middle part" of the string. Using your last example for demonstration purposes, you left the first 6 and last 13 characters, so what you removed hardly qualifies as the "middle part" or the text (removing the middle part would have left the same number of characters from before and after whatever was removed). You need to show us real examples of your text and tell us how you are identifying what needs to be dropped from those examples.
 
Upvote 0
Thanks Rick,

What I’m trying to do is to leave beginning and the end and drop middle part that contains different characters in each row.

Here is another example.

This is what I have

Creative:BAN_XXX_AAA_100X100_AAA_DEMO_OPX_SINGLE
Creative:BAN_XXX_AAA_100X100_AAA_DEMO_PMT_889NA_Married
Creative:BAN_XXX_AAA_100X100_AAA_DEMO_CONTX_Family

The part I need to drop contains different characters and varies in length.

I need something like this

Creative: BAN_XXX_AAA_Single
Creative: BAN_XXX_AAA_Married
Creative: BAN_XXX_AAA_Family

I hope this makes sense.

Thank you.
 
Upvote 0
Hi,

Assuming we always start with the third "_"

=LEFT(A1,FIND("*",SUBSTITUTE(A1,"_","*",3)))&MID(SUBSTITUTE(A1,"_","*",LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))),FIND("*",SUBSTITUTE(A1,"_","*",LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))))+1,10)
 
Upvote 0
Try this
Enter in B1 and copy down
Code:
[B]=SUBSTITUTE(TRIM(LEFT(SUBSTITUTE(A1,"_",REPT(" ",100)),300))," ","_")&"_"&TRIM(RIGHT(SUBSTITUTE(A1,"_",REPT(" ",50)),50))[/B]

Book1
AB
1Creative:BAN_XXX_AAA_100X100_AAA_DEMO_OPX_SINGLECreative:BAN_XXX_AAA_SINGLE
2Creative:BAN_XXX_AAA_100X100_AAA_DEMO_PMT_889NA_MarriedCreative:BAN_XXX_AAA_Married
3Creative:BAN_XXX_AAA_100X100_AAA_DEMO_CONTX_FamilyCreative:BAN_XXX_AAA_Family
Sheet4
 
Upvote 0
Try this
Enter in B1 and copy down
Code:
[B]=SUBSTITUTE(TRIM(LEFT(SUBSTITUTE(A1,"_",REPT(" ",100)),300))," ","_")&"_"&TRIM(RIGHT(SUBSTITUTE(A1,"_",REPT(" ",50)),50))[/B]
#DAE7F5 " />#DAE7F5 ;text-align: center;color: #161120">
AB
Creative:BAN_XXX_AAA_100X100_AAA_DEMO_OPX_SINGLECreative:BAN_XXX_AAA_SINGLE
Creative:BAN_XXX_AAA_100X100_AAA_DEMO_PMT_889NA_MarriedCreative:BAN_XXX_AAA_Married
Creative:BAN_XXX_AAA_100X100_AAA_DEMO_CONTX_FamilyCreative:BAN_XXX_AAA_Family

<colgroup><col style="width: 25pxpx" https:="" www.mrexcel.com="" forum="" usertag.php?do="list&action=hash&hash=DAE7F5"" target="_blank"></colgroup><colgroup><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]

[TD="align: center"]3[/TD]

</tbody>
#DAE7F5 ;color: #161120">Sheet4

Wow! Thank you, AlKey! Worked like a magic! :)
 
Upvote 0
Hi,

Another way, a bit shorter:


Book1
AB
1Creative:BAN_XXX_AAA_100X100_AAA_DEMO_OPX_SINGLECreative:BAN_XXX_AAA_ SINGLE
2Creative:BAN_XXX_AAA_100X100_AAA_DEMO_PMT_889NA_MarriedCreative:BAN_XXX_AAA_ Married
3Creative:BAN_XXX_AAA_100X100_AAA_DEMO_CONTX_FamilyCreative:BAN_XXX_AAA_ Family
Sheet289
Cell Formulas
RangeFormula
B1=TRIM(LEFT(A1,FIND(" ",SUBSTITUTE(A1,"_"," ",3)))&RIGHT(SUBSTITUTE(A1,"_",REPT(" ",99)),99))
 
Upvote 0
A little bit shorter:)
Code:
[B]=LEFT(A1,FIND("_",A1,FIND("_",A1)+5))&TRIM(RIGHT(SUBSTITUTE(A1,"_",REPT(" ",50)),50))[/B]
 
Upvote 0
Don't know if OP has varying length of Text string before the 3rd underscore, but that assumes the fixed length of 3 characters in between 2nd and 3rd underscores, so it may or may not work.

If we were to make the assumption that the leading Text is fixed length, then even this will do:

=LEFT(A1,21)&TRIM(RIGHT(SUBSTITUTE(A1,"_",REPT(" ",99)),99))
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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