+ Reply to Thread
Results 1 to 4 of 4

Extract Address and phone numbers

Hybrid View

  1. #1
    Registered User
    Join Date
    02-14-2010
    Location
    sacramento,ca
    MS-Off Ver
    Excel 2003
    Posts
    6

    Extract Address and phone numbers

    Hello

    I have a spread sheet with bunch of raw data and its all in colum A, within that data there are 4 fields, Name, address, city state zip, phone number, I'm looking to extract that information from column A in to column, b, c, d, e, the macro suppose to grab that text from those 4 rows and just make 1 row, and placed that data in Column B, C, D and E, the macro should search for the entire sheet for those records.

    Thanks.


    here is the data.


    Oklahoma l
    Oregon l
    Pennsylvania l
    Rhode Island l
    South Carolina l
    South Dakota l
    Tennessee l
    Texas l
    Utah l
    Vermont l
    Virginia l
    Washington l
    West Virginia l
    Wisconsin l
    Wyoming l
    Lint, Michael G
    2917 Ninth Ave
    Sacramento, CA 95818-4046
    (916) 446-4218
    Find Neighbors l
    Map and Driving Directions l
    Printer-Friendly l
    Send Listing to my Email l
    Find Nearby Businesses l
    Type: Land Line
    SPONSORED LINKS
    Listing date Nov. 2009
    Local Information for Sacramento, CA
    Population: 407,018 l

  2. #2
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394

    Re: Extract Address and phone numbers

    How would I now which data belongs to which record?
    Plus I can see a lot more than 4 fields

  3. #3
    Registered User
    Join Date
    02-14-2010
    Location
    sacramento,ca
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Extract Address and phone numbers

    Quote Originally Posted by Mallycat View Post
    How would I now which data belongs to which record?
    Plus I can see a lot more than 4 fields

    As you can see below, its just raw data then there is some data that meaningful like the name, address, city state zip (all in column A) and then phone number

    I have a word macro that does that job of taking the record out, since I can do a search in the area code prefix, e.g. Look for Open parenthesis then look for any text inside the parenthesis an then any text and then any text and then close parenthesis and that fixes the location to the area code and once the area code is detected I will select that line and up 3 more and cut it out and page in a new word document. But the process is TOO SLOW.

    In excel it might look for the area code and work up 3 rows and put that data across the column in one row but multiple columns in a format like

    name, adress, city state zip, phone number

    Any help would be appreciated.

    thanks



    The data just flow like this
    garbage
    garbage
    garbage
    garbage
    garbage
    garbage
    james smith
    123 abc street
    new york, ny, 12345
    (212) 555-5555
    garbage
    garbage
    garbage
    garbage
    garbage
    james woo
    456 abc street
    new york, ny, 12345
    (213) 555-5555
    garbage
    garbage
    Last edited by donlincolnef; 02-14-2010 at 01:54 PM.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Extract Address and phone numbers

    Hello ,

    This macro will copy the address fields to single a row in columns "B:E" of the active sheet. The macro assumes the following conditions:
    1. Data is in column "A" and starts at cell A2 with a header in A1.
    2. The address is always 4 lines with the telephone number in the last line.
    3. Telephone numbers do not start with the long distance prefix "1-".
    4. Valid separators in a telephone number are a single space or hyphen.
    5. Area code is optional. Parentheses around the area code are also optional.
    Sub ListAddresses()
    
      Dim Data() As Variant
      Dim I As Long
      Dim RegExp As Object
      Dim Rng As Range
      Dim RngEnd As Range
      Dim Wks As Worksheet
      
        Set Wks = Worksheets("Sheet1")
        
        Set Rng = Wks.Range("A2")
        Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
        Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Wks.Range(Rng, RngEnd))
        
        ReDim Data(1 To Rng.Rows.Count, 1 To 1)
        Data = Rng.Value
        
       'Create a Regular Expression for pattern matching
        Set RegExp = CreateObject("VBScript.RegExp")
        RegExp.IgnoreCase = True
        
       'Valid telephone number pattern
        RegExp.Pattern = "^(\(\d{3}\)|\d{3})?[-\s]?\d{3}[-\s]?\d{4}"
        
         'Test if data is telephone number
          For I = 1 To UBound(Data)
            If RegExp.Test(Data(I, 1)) Then
             'Copy the address fields to a single row in columns B:E
              Rng.Cells(I - 3, 2).Resize(1, 4) = WorksheetFunction.Transpose(Rng.Cells(I - 3, 1).Resize(4, 1))
            End If
          Next I
          
       'Release the object reference and memory
        Set RegExp = Nothing
        
    End Sub
    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time.
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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