+ Reply to Thread
Results 1 to 4 of 4

Lookup function for phone numbers to countries

Hybrid View

  1. #1
    Registered User
    Join Date
    02-26-2015
    Location
    Israel
    MS-Off Ver
    2013
    Posts
    8

    Lookup function for phone numbers to countries

    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.
    Last edited by berkeleyjake; 10-22-2015 at 08:07 AM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,611

    Re: Lookup function for phone numbers to countries

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  3. #3
    Registered User
    Join Date
    02-26-2015
    Location
    Israel
    MS-Off Ver
    2013
    Posts
    8

    Re: Lookup function for phone numbers to countries

    Forum Test.xlsx

    Sheet attached

    The E column is where the formula is and should display the country for which the country code is for in the number in the array on the other sheet.

    The formula that is there now is just my idea for what should happen. Totally welcome to a completely different formula if it works.
    Last edited by berkeleyjake; 10-22-2015 at 08:50 AM.

  4. #4
    Registered User
    Join Date
    02-26-2015
    Location
    Israel
    MS-Off Ver
    2013
    Posts
    8

    Re: Lookup function for phone numbers to countries

    I got it to work... just had to play with it for a bit. the formula ended up being:
    =IFERROR(VLOOKUP(NUMBERVALUE(LEFT(D5,4)),Sheet3!A:B,2,0),IFERROR(VLOOKUP(NUMBERVALUE(LEFT(D5,3)),Sheet3!A:B,2,0),IFERROR(VLOOKUP(NUMBERVALUE(LEFT(D5,2)),Sheet3!A:B,2,0),IFERROR(VLOOKUP(NUMBERVALUE(LEFT(D5,1)),Sheet3!A:B,2,0),"?"))))

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 8
    Last Post: 11-19-2014, 06:12 PM
  2. Replies: 9
    Last Post: 11-05-2013, 11:06 PM
  3. Macro or Function to extract phone numbers and emails from a string
    By jz789 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2013, 10:32 PM
  4. [SOLVED] Macro or Function to extract phone numbers and emails from a string
    By jz789 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-28-2013, 10:31 PM
  5. Excel 2007 : Lookup Phone numbers
    By revipod in forum Excel General
    Replies: 2
    Last Post: 01-27-2012, 09:41 PM
  6. Replies: 2
    Last Post: 06-23-2006, 02:00 PM
  7. Replies: 1
    Last Post: 02-11-2005, 01:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1