+ Reply to Thread
Results 1 to 2 of 2

Separating an address string into separate parts using vba

  1. #1
    Registered User
    Join Date
    05-18-2010
    Location
    Bermuda
    MS-Off Ver
    Excel 2003
    Posts
    4

    Separating an address string into separate parts using vba

    Hello,

    I have an address string that I need to split up into three cells using vba with the mid, right, and left functions. The problem that I'm having is that I can't seem to formulate the functions in which they can handle different forms of the address.

    For example,

    New York, NY 23658 should return New York in one cell, NY in the next, and 23658 in the next.

    New York, NY should return New York in one cell, NY in the next, and nothing in the next because there isn't a zip code.

    The code I have for the first example is:


    Please Login or Register  to view this content.
    This code works. I just need to amend it for the second example.

    Thanks in advance,
    Last edited by adhbrown; 06-30-2010 at 10:53 AM.

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

    Re: Separating an address string into separate parts using vba

    Hello adhbrown,

    You may be able to use this macro. It is part of a lager macro I wrote to handle mail addresses for both the US and Canada. It may require some tweaking to make it work with your code. The macro examines the cells in a column. If those cells contain an address line with the city, state, and zip (optional) then first cell will be the city name, the cell one column to the right will be the state, and the cell two cells to the right will be the Zip, if there is one.
    Please Login or Register  to view this content.

    Example: Using the Macro
    Please Login or Register  to view this content.
    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)

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