Ozgrid Excel Help & Best Practices Forums


XL Templates | XL Add-ins | XL Training | XL Estimating | XL Scheduling | XL Recovery | XL Trading | XL Financial | XL Conversion | XL Charting


+ Reply to Thread
Results 1 to 4 of 4

Thread: Telepone Number As String, Compare and Strip to Area Code

  1. #1
    Join Date
    16th July 2005
    Posts
    3

    Telepone Number As String, Compare and Strip to Area Code


    Download Active Data For Excel > > DETAILS > >
    I am working on a macro that will take a list of phone numbers from a report and strip them down to the area code or international code. The major problems are as follows:

    1) Telephone numbers are stored as strings because of how they are imported in to Excel
    2) Not all telephones numbers are reported correctly. Some numbers will be reported as "Unknown", "408" or missing the last 2-4 digits. Others numbers will be only 4 digits; these are internally dialed numbers therefore digits will be changed to area code 919.
    3) Most numbers will have "81" as the first two characters then the area code.

    So examples of what the cells would contain and what result of macro should be:
    Type of Call Cell Value Result
    External Call 819196772499 919
    International Call 8011498946261990 011
    Internal Call 2466 919
    Only Area Code 408 408
    Unknown Unknown Unknown

    Is there a way to compare the string to "Unknown"? and then Count how many digits there are and strip digits off both sides (if needed)?

    Thanks in Advance
    MAC

  2. #2
    Join Date
    16th July 2005
    Posts
    3

    Re: Telepone Number As String, Compare and Strip to Area Code

    Clarfication:
    The cell would contain either a number or "Unknown". Thats it.
    Comparing and striping these numbers will not be the only thing the macro is doing but it is the only thing I having trouble with.
    Thanks
    MAC

  3. #3
    Join Date
    20th May 2003
    Location
    Mesa, Az
    Posts
    1,115

    Re: Telepone Number As String, Compare and Strip to Area Code

    Welcome to the Forum!!!

    Quote Originally Posted by mac7attack
    So examples of what the cells would contain and what result of macro should be:
    Type of Call Cell Value Result
    External Call 819196772499 919
    International Call 8011498946261990 011
    Internal Call 2466 919
    Only Area Code 408 408
    Unknown Unknown Unknown
    HINT:
    External call: Length of cell value is 12, you could use MID(cell ref,3,3)
    Int'l call: Length of cell value is 14, you could use MID(cell ref,2,3)
    Internal call: Length of cell value is 4, you could use "919"
    Only area code: Length of cell value is 3, you could simply return the cell ref value
    Unknown: Length of cell value is 7, you could simply return the cell ref value

    Using the HINT from above, you could use a nested IF, or more preferrably, a SELECT CASE in your code to return the values to the appropriate cells. Of course, the inclusion of the TRIM function to eliminate any unnecessary spaces would also help.

    HTH,

  4. #4
    Join Date
    16th July 2005
    Posts
    3

    Re: Telepone Number As String, Compare and Strip to Area Code


    Create Excel dashboards quickly with Plug-N-Play reports.
    Thanks a bunch HTH

    mid and select case made it work wonderfully

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Possible Answers

  1. Compare and find a string
    By adetuc in forum EXCEL HELP
    Replies: 3
    Last Post: July 26th, 2006, 10:20
  2. Use number from text string in code?
    By Jaz in forum EXCEL HELP
    Replies: 2
    Last Post: April 11th, 2005, 18:34
  3. Convert a number to string and add to string
    By alnew in forum EXCEL HELP
    Replies: 5
    Last Post: January 26th, 2005, 12:04
  4. Replies: 4
    Last Post: November 16th, 2004, 16:43
  5. Replies: 2
    Last Post: November 11th, 2004, 21:54

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