Find the Country in a set of words

datastudent

Board Regular
Joined
Sep 7, 2021
Messages
91
Office Version
  1. 365
Platform
  1. Windows
Hi,

I don't know how to explain this clearly so please be patient with me.

In column C, I have a formula where I look for the "Fixed" and "Mobile" only. What I want is to also show the country name if in column A it only show the country name as shown below.

Template_v1.xlsm
AC
3Outbound Destinationa
22AustraliaAustralia
23Australia Emergency 
24Australia FixedFixed
26Australia MobileMobile
52BrazilBrazil
53Brazil - EMS 
54Brazil - Freephone 
55Brazil - MobileMobile
81Czech RepublicCzech Republic
82Czech Republic 112 
83Czech Republic Freephone 
84Czech Republic MobileMobile
85Czech Republic Shared 
iBASIS_Outbound
Cell Formulas
RangeFormula
C23:C24,C26,C82:C85,C53:C55C23=IFERROR(ARRAYTOTEXT(REGEXEXTRACT($A23,"Mobile|Fixed",1)),"")
 
If you have a lookup table of countries like this:

Book1
A
1Countries
2Albania
3Australia
4Benin
5Brazil
6Czech Republic
7Denmark
8England
9
10
Sheet3


Then you can use a formula like this:

Book1
AC
3Outbound Destination
22AustraliaAustralia
23Australia Emergency 
24Australia FixedFixed
26Australia MobileMobile
52BrazilBrazil
53Brazil - EMS 
54Brazil - Freephone 
55Brazil - MobileMobile
81Czech RepublicCzech Republic
82Czech Republic 112 
83Czech Republic Freephone 
84Czech Republic MobileMobile
85Czech Republic Shared 
Sheet2
Cell Formulas
RangeFormula
C22:C24,C26,C52:C55,C81:C85C22=LET(c,Sheet3!$A$2:$A$20,mf,{"Mobile","Fixed"},XLOOKUP(A22,c,c,XLOOKUP(TRUE,ISNUMBER(SEARCH(mf,A22)),mf,"",0),0))
 
Upvote 0
Solution
Bit of a guess from your sample data, but could either of these work for you?

25 02 19.xlsm
ABCD
22AustraliaAustraliaAustralia
23Australia Emergency  
24Australia FixedFixedFixed
26Australia MobileMobileMobile
52BrazilBrazilBrazil
53Brazil - EMS  
54Brazil - Freephone  
55Brazil - MobileMobileMobile
81Czech RepublicCzech RepublicCzech Republic
82Czech Republic 112  
83Czech Republic Freephone  
84Czech Republic MobileMobileMobile
85Czech Republic Shared  
Country
Cell Formulas
RangeFormula
C22:C24,C26,C52:C55,C81:C85C22=IF(A22="","",IFNA(REGEXEXTRACT($A22,"Mobile|Fixed",1),IF(A22=LEFT(A23,LEN(A22)),A22,"")))
D22:D24,D26,D52:D55,D81:D85D22=IF(A22="","",IFNA(REGEXEXTRACT($A22,"Mobile|Fixed",1),IF(COUNT(MATCH(A22&"*"&{"Fixed","Mobile","Freephone","Emergency","EMS","Shared"},A23:A$1000,0)),A22,"")))
 
Upvote 0
Bit of a guess from your sample data, but could either of these work for you?

25 02 19.xlsm
ABCD
22AustraliaAustraliaAustralia
23Australia Emergency  
24Australia FixedFixedFixed
26Australia MobileMobileMobile
52BrazilBrazilBrazil
53Brazil - EMS  
54Brazil - Freephone  
55Brazil - MobileMobileMobile
81Czech RepublicCzech RepublicCzech Republic
82Czech Republic 112  
83Czech Republic Freephone  
84Czech Republic MobileMobileMobile
85Czech Republic Shared  
Country
Cell Formulas
RangeFormula
C22:C24,C26,C52:C55,C81:C85C22=IF(A22="","",IFNA(REGEXEXTRACT($A22,"Mobile|Fixed",1),IF(A22=LEFT(A23,LEN(A22)),A22,"")))
D22:D24,D26,D52:D55,D81:D85D22=IF(A22="","",IFNA(REGEXEXTRACT($A22,"Mobile|Fixed",1),IF(COUNT(MATCH(A22&"*"&{"Fixed","Mobile","Freephone","Emergency","EMS","Shared"},A23:A$1000,0)),A22,"")))
The first formula works for some but for some it does not.

Template_v1.xlsm
AD
3Outbound Destinationa
49Bolivia 
50Bosnia and HerzegovinaBosnia and Herzegovina
60Cambodia 
61ChileChile
66China 
67ColombiaColombia
92Ecuador 
93El Salvador - FixedFixed
iBASIS_Outbound
Cell Formulas
RangeFormula
D49:D50,D60:D61,D66:D67,D92:D93D49=IF(A49="","",IFNA(REGEXEXTRACT($A49,"Mobile|Fixed",1),IF(A49=LEFT(A50,LEN(A49)),A49,"")))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1:A310,A388:A1048576Cell ValueduplicatestextNO
 
Upvote 0
If you have a lookup table of countries like this:

Book1
A
1Countries
2Albania
3Australia
4Benin
5Brazil
6Czech Republic
7Denmark
8England
9
10
Sheet3


Then you can use a formula like this:

Book1
AC
3Outbound Destination
22AustraliaAustralia
23Australia Emergency 
24Australia FixedFixed
26Australia MobileMobile
52BrazilBrazil
53Brazil - EMS 
54Brazil - Freephone 
55Brazil - MobileMobile
81Czech RepublicCzech Republic
82Czech Republic 112 
83Czech Republic Freephone 
84Czech Republic MobileMobile
85Czech Republic Shared 
Sheet2
Cell Formulas
RangeFormula
C22:C24,C26,C52:C55,C81:C85C22=LET(c,Sheet3!$A$2:$A$20,mf,{"Mobile","Fixed"},XLOOKUP(A22,c,c,XLOOKUP(TRUE,ISNUMBER(SEARCH(mf,A22)),mf,"",0),0))
I would want something more simpler without the lookup table but this one works best. Thank you!
 
Upvote 0
Follow up question:

How do I extract the Country only on the same data?

Column 1 is the data and Column 2 is the expected result.

ALBANIA FIXEDALBANIA
ANGOLA MOBILEANGOLA
ARGENTINA - MOBILEARGENTINA
ARMENIAARMENIA
BOSNIA AND HERZEGOVINA MOBILEBOSNIA AND HERZEGOVINA
 
Upvote 0
If you have a lookup table of countries like this:

Book1
A
1Countries
2Albania
3Australia
4Benin
5Brazil
6Czech Republic
7Denmark
8England
9
10
Sheet3


Then you can use a formula like this:

Book1
AC
3Outbound Destination
22AustraliaAustralia
23Australia Emergency 
24Australia FixedFixed
26Australia MobileMobile
52BrazilBrazil
53Brazil - EMS 
54Brazil - Freephone 
55Brazil - MobileMobile
81Czech RepublicCzech Republic
82Czech Republic 112 
83Czech Republic Freephone 
84Czech Republic MobileMobile
85Czech Republic Shared 
Sheet2
Cell Formulas
RangeFormula
C22:C24,C26,C52:C55,C81:C85C22=LET(c,Sheet3!$A$2:$A$20,mf,{"Mobile","Fixed"},XLOOKUP(A22,c,c,XLOOKUP(TRUE,ISNUMBER(SEARCH(mf,A22)),mf,"",0),0))
What if instead of getting the country name I want to it to return as "AAA"?
 
Upvote 0
Assuming you have a table of countries, you can do this:

Book1
ABCDEFG
1CountriesCode
2ALBANIA FIXEDALBANIAAAAALBANIAAAA
3ANGOLA MOBILEANGOLABBBANGOLABBB
4ARGENTINA - MOBILEARGENTINACCCARGENTINACCC
5ARMENIAARMENIAAAAARMENIAAAA
6BOSNIA AND HERZEGOVINA MOBILEBOSNIA AND HERZEGOVINAEEEAUSTRALIADDD
7AUSTRALIA - FIXEDAUSTRALIADDDBOSNIA AND HERZEGOVINAEEE
8ZAIREZAIREZZZBOLIVIAFFF
9ANGOLA FIXEDANGOLABBBCOLOMBIAGGG
10DENMARKBBB
11ETHIOPIAAAA
12ZAIREZZZ
13
Sheet6
Cell Formulas
RangeFormula
B2:B9B2=XLOOKUP(TRUE,ISNUMBER(SEARCH($F$2:$F$12,A2)),$F$2:$F$12,"",0)
C2:C9C2=XLOOKUP(TRUE,ISNUMBER(SEARCH($F$2:$F$12,A2)),$G$2:$G$12,"",0)


The B formula will return the name. If you have a second column on your country table, like column G here, you can use the C formula to get AAA or whatever you prefer.

Incidentally, there's a formula available to earlier versions of Excel that's a bit of a trick, but it's shorter and still works:

Excel Formula:
=LOOKUP(2,1/SEARCH($F$2:$F$12,A2),$F$2:$F$12)
 
Upvote 0
The first formula works for some but for some it does not.
What about the second formula I suggested?
If that also does not work (hard to tell when most of the rows of the sample data are hidden) then I am in agreement with Eric that a lookup table would be required.
 
Upvote 0
Assuming you have a table of countries, you can do this:

Book1
ABCDEFG
1CountriesCode
2ALBANIA FIXEDALBANIAAAAALBANIAAAA
3ANGOLA MOBILEANGOLABBBANGOLABBB
4ARGENTINA - MOBILEARGENTINACCCARGENTINACCC
5ARMENIAARMENIAAAAARMENIAAAA
6BOSNIA AND HERZEGOVINA MOBILEBOSNIA AND HERZEGOVINAEEEAUSTRALIADDD
7AUSTRALIA - FIXEDAUSTRALIADDDBOSNIA AND HERZEGOVINAEEE
8ZAIREZAIREZZZBOLIVIAFFF
9ANGOLA FIXEDANGOLABBBCOLOMBIAGGG
10DENMARKBBB
11ETHIOPIAAAA
12ZAIREZZZ
13
Sheet6
Cell Formulas
RangeFormula
B2:B9B2=XLOOKUP(TRUE,ISNUMBER(SEARCH($F$2:$F$12,A2)),$F$2:$F$12,"",0)
C2:C9C2=XLOOKUP(TRUE,ISNUMBER(SEARCH($F$2:$F$12,A2)),$G$2:$G$12,"",0)


The B formula will return the name. If you have a second column on your country table, like column G here, you can use the C formula to get AAA or whatever you prefer.

Incidentally, there's a formula available to earlier versions of Excel that's a bit of a trick, but it's shorter and still works:

Excel Formula:
=LOOKUP(2,1/SEARCH($F$2:$F$12,A2),$F$2:$F$12)
Okay I will add the Country code. But I still want to show the "Fixed" and "Mobile". How do I combine that to the initial formula?

=LET(c,Note!$E$2:$E$80,mf,{"Mobile","Fixed"},XLOOKUP(A4,c,c,XLOOKUP(TRUE,ISNUMBER(SEARCH(mf,A4)),mf,"",0),0))
 
Upvote 0

Forum statistics

Threads
1,226,837
Messages
6,193,254
Members
453,784
Latest member
Chandni

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