I am having a bit of difficulty doing a lookup function to check phone numbers to show their country.
Because the country codes can be anywhere from 1-4 digits, I can't think of a formula that will check the first 1-4 digits of the phone number based on the index of country codes.
Additionally, I need it to be able to differentiate US territories from the mainland. So Jamaica which starts with a 1876 would need to show up as Jamaica and not USA/Canada. Same with American Samoa (1684) and many others.
Any help would be great.
The Countries and Codes are arranged in a table such as:
A B
Country Name Country Code
USA/Canada 1
Russia/Kazakhstan 7
Egypt 20
Jamaica 1876
St. Kitts/Nevis 1869
Myanmar 95
Iran 98
Morocco 212
For an example, I tried the following
=IFERROR(VLOOKUP(LEFT(D7,4),Sheet3!A:B,2,0),IFERROR(VLOOKUP(LEFT(D7,3),Sheet3!A:B,2,0),IFERROR(VLOOKUP(LEFT(D7,2),Sheet3!A:B,2,0),IFERROR(VLOOKUP(LEFT(D7,1),Sheet3!A:B,2,0),"?"))))
I assumed that this would lookup the first 4 digits of the phone number and check it against the country code array and return the country. If it doesn't find it, it would look up the first 3 digits only and so on and so on. And if it can't find any, it just will return the ? symbol. But that doesn't work.
D7 is the first cell in the column with the phone number, Sheet3 contains the array of country codes and countries with column A having the codes and column B having the country names.
Bookmarks