Extract characters from text in cell

ExGus

Board Regular
Joined
May 2, 2012
Messages
53
DEU - video_PMP_deal - DE - all sites - Group M IKEA RON Pre- & Mid
INT - video_PMP_deal - IT - all sites - PHD_TTD July_July 21

Hi, I want to extract the country code from a column. In this example, it is DE and IT but is not always in the same place as people that input info adds extra spaces but the country code should appear between "-" and "-".
What's the best way to do it knowing the country code will always be two characters but might not always be in the same position.
Thanks
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi,

As you described, country code is Always 2 characters sandwiched between hyphens at random positions within text string,
assuming there are no other 2 character strings other than the country code, try:

Book3.xlsx
AB
1DEU - video_PMP_deal - DE - all sites - Group M IKEA RON Pre- & MidDE
2INT - video_PMP_deal - IT - all sites - PHD_TTD July_July 21IT
3DEU - video_PMP_deal - all sites - Group M IKEA RON Pre- & -DE - MidDE
Sheet726
Cell Formulas
RangeFormula
B1:B3B1=MID(SUBSTITUTE(A1," ",""),SEARCH("-??-",SUBSTITUTE(A1," ",""))+1,2)
 
Upvote 0
Solution
You're welcome, glad to help.
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,581
Members
449,089
Latest member
Motoracer88

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