+ Reply to Thread
Results 1 to 4 of 4

Parsing out text

  1. #1
    Registered User
    Join Date
    08-31-2005
    Posts
    5

    Parsing out text

    Hi,

    I have a column of alpha-numeric strings with an address in the middle as follows:

    John Doe 06 CH 1837 123 Any St, Any Town, IL 60612 Pierce & Associates

    The red text (the address) is what I want to cut from this string and move to an adjacent column.

    The string starts with a name of any length, but I know that every string has the blue text that always starts with CH and then is followed by a space and four integers as shown above. The numbers change but the CH is constant.

    So I know that I need to search each line for CH, move to the right 5 spaces past that (to the beginning of the address), and cut everything up until the end of the next 5 integers (the zip code), then move it to the next column. And then some sort of loop applied.

    I know what I need done I just don't know how to write the macro. Can anyone please help. Many thanks in advance.

    EDIT: By the way the text in the workbook is not colored red or blue, only here for purpose of illustration.

    Ryan
    Last edited by VBA Noob; 02-10-2007 at 07:53 PM.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Rysn

    Try this macro

    Replace the red a with the column letter that has the text to be parsed.

    The macro places the address in the next column to the right of the text to be parsed - eg list in column A, Address will be placed in column B

    I have also added 2 other options in the code
    Option 1
    replace name, address, company entry with name, company
    Option 2
    Place name, company details in the 2nd column to the right of the list

    To enable 1 or both of these option remove the ' from the front of the lines of code in blue

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-31-2005
    Posts
    5
    Thanks a bunch mudraker,

    Everything works pretty good including the options you put in. The only thing is that for some reason about 10% of the lines are truncated or have additional text past the zip code. I don't see any commonality between the strings that have this problem.

    Here are a couple examples where the red is the output column:

    Kiril Krkolev 06 CH 1729 150 Enclave Cricle Unit C, Bolingbrook,IL 60440 Codilis & Associates 150 Enclave Cricle Unit C, Bolingbr

    Aida R Dismaya 06 CH 1604 2282 Twilight Drive, Aurora, IL 60504 Weltman, Weinberg & Reis 2282 Twilight Drive, Aurora, IL 60504 Weltman, Weinberg

    Matthew Larkins 06 CH 1692 2823 Sheffield, New Lenox, IL 60451 Hauselman, Rappin & Olswang 2823 Sheffield, New Lenox, IL 60451 Hauselman, Rappin &

    Any ideas?

    Ryan
    Last edited by halfordryan; 02-10-2007 at 09:37 PM.

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    It is caused by the cmpany name having a comma in it.

    The macro is programmed to look for the last comma and assumes that it is the devider between the zip code and the company name.

    If the state abbreviation of IL is the only one listed in the data to be parsed then I can change the macro to look for IL instead of the last comma.

    Another option is that if there are always only 2 comma's after the CH then I could also change the macro to work off the 2nd comma after the CH

+ 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