+ Reply to Thread
Results 1 to 10 of 10

Parsing City State and Zip Code

  1. #1
    Registered User
    Join Date
    08-23-2014
    Location
    Miami, USA
    MS-Off Ver
    365
    Posts
    69

    Unhappy Parsing City State and Zip Code

    I'm trying to split a column with cells containing City, state and zip code in them. I would like to have a column for City, State and Zip Code respectively. The attached file is just a sample, but I would be using cities from all over the US.

    Thanks
    Attached Files Attached Files
    Last edited by sandy1977; 08-26-2014 at 10:05 PM. Reason: Updated Spreadsheet

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Parsing City State and Zip Code

    Try this it worked for me

    http://www.dummies.com/how-to/conten...n-excel-2.html

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Parsing City State and Zip Code

    Hi,

    State:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Zip:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    08-23-2014
    Location
    Miami, USA
    MS-Off Ver
    365
    Posts
    69

    Re: Parsing City State and Zip Code

    Hi guys, I'm trying to write VBA code for it, please help.

    Thanks

  5. #5
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Parsing City State and Zip Code

    What specific problem do you have with your code? Can you post what you have tried so far?


    Sent from my iPad using Tapatalk

  6. #6
    Registered User
    Join Date
    08-23-2014
    Location
    Miami, USA
    MS-Off Ver
    365
    Posts
    69

    Re: Parsing City State and Zip Code

    coolblue, here is what I have, thanks to another thread where Leith Ross wrote some VBA code to separate an address string into separate parts using vba. I went ahead and tried to use Leith's code but the problem is that in some of the cells the ZIP CODE or CITY are missed and not copied to the corresponding column. Please see attached spreadsheet and run the Sub TestParseCityStateZip() to see what I'm talking about.

    Any help is appreciated.


    Thanks

  7. #7
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Parsing City State and Zip Code

    Quote Originally Posted by sandy1977 View Post
    Hi guys, I'm trying to write VBA code for it, please help.

    Thanks
    How are you trying to do this?
    Post what you have written so far. The code in the attached sheet is original, how have you tried to modify it?

    Meanwhile, here are some links that explain regular expressions...

    http://strugglingtoexcel.wordpress.c...ssions-in-vba/
    http://www2.hawaii.edu/~chenx/readin...vb_regexp.html
    http://msdn.microsoft.com/en-us/libr...1x(VS.85).aspx

    and this...
    http://regex101.com/
    Last edited by coolblue; 08-27-2014 at 03:56 AM.

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Parsing City State and Zip Code

    Quote Originally Posted by sandy1977 View Post
    Hi guys, I'm trying to write VBA code for it, please help.

    Thanks
    Hi,

    Please note that you should explain all your requirements in the text of your post. There was no mention of VBA in your original.
    In addition, please note the forum rules about starting new threads and linking to existing threads that deal with the same problem. As a minimum you should have posted a link to the other.

    Finally if you do need VBA one way would be to use the method I suggested in post #3 an have VBA create and then copy the formulae for you. Then copy the formulae and paste them back as values with the macro.
    Last edited by Richard Buttrey; 08-27-2014 at 06:43 AM.

  9. #9
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Parsing City State and Zip Code

    hi sandy1977, VB option, please check attachment, press Run button or run code "test" (ALT+F8, select "test", Run)
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    08-23-2014
    Location
    Miami, USA
    MS-Off Ver
    365
    Posts
    69

    Re: Parsing City State and Zip Code

    coolblue and Richard, I apologize, I´m a newbie to this forum and to VBA as well. Certainly I appreciate the links and help given, I will definitely learn from this mistake(s). Richard I thought I was posting my thread under the VBA section of the forum but I will be more specific next time I post, I understand where you are coming from, it´s just easier for everyone reading my post.

    And last but not least, WATERSEV, that works perfectly, just what I needed, thank you so much for your help and everyone that posted to this thread.

  11. #11
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Parsing City State and Zip Code

    For anyone interested in root cause, the problem with the file is that there are non-breaking space characters (UNICODE 160) instead of normal (ASCII 32) space characters between the comma and the state code. This was causing the regular expression to fail and that's why the state codes were not printing. The original code from @leithross can be fixed in two ways...

    1. Use \b instead of \s in the regular expressions to detect the word boundaries (as in the solution from @waterserv)
    2. Use a regular expression to replace the non-breaking spaces with regular ones
    Please Login or Register  to view this content.

+ 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. autofill city and state when typing in zip code
    By shughes6288 in forum Excel General
    Replies: 7
    Last Post: 01-07-2016, 12:35 PM
  2. [SOLVED] Parsing Out City and State Formula
    By dash11 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-28-2014, 04:49 PM
  3. zip code to city, state function
    By xip in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-07-2012, 10:12 PM
  4. Web lookup query (have: city & state | want: zip code)
    By avatarr in forum Excel General
    Replies: 0
    Last Post: 04-07-2010, 10:49 PM
  5. zip code to city, state function
    By xcelentform in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-18-2006, 07:10 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