+ Reply to Thread
Results 1 to 3 of 3

Free Macro to convert a column with City State Zip to 3 columns

  1. #1
    Registered User
    Join Date
    08-17-2015
    Location
    Grand Haven, Michigan
    MS-Off Ver
    Office 365
    Posts
    2

    Lightbulb Free Macro to convert a column with City State Zip to 3 columns

    Hi all. I've been a lurker for 2023 days according to the banner. I've come here a lot looking for help on formulas so it is time to give back.

    I run a print shop and I get mailing lists all the time. For some reason beyond my comprehension a lot come with "city state zip" all in one column. Yeah, if you're lucky, you can uses text to columns and break it on the comma first to get "City" and "State Zip" and then by space to break "State Zip" into 2 columns. Then go back and do a find and replace on the state column to get rid of the space at the start.

    But I find that on long lists I have a problem with manual entries. What if there is no comma? What if there are extra spaces? It's a mixed bag. And you can't just 'text to columns' on Space, because what if the city name has two words? Like "New York" or "Las Vegas" ? That throws it off too.

    So after years of dealing with this by hand, I figured it was time to put together a macro (and a function which could have been part of the macro) that solves 'most' of it. I've added a lot of comments to try and explain what is going on in the macro. But basically, it strips out extra spaces and puts everything into an array based on space as a delimiter. Then works from the end of the array to find the zip, the state, and then adds the rest together to get the city. It preserves leading zeros and Zip+4 zip codes by using a '.

    Known Failures:
    1. This is for US addressing.
    2. If your state is two words instead of a 2 letter abbreviation, it will produce the wrong results, but not tell you that.

    I hope you find this useful, if you have any corrections/improvements, I'd love to hear them.

    after installing it the basic usage is as follows:

    1. make sure you have 3 empty columns to the right of the range that you want to convert.
    2. Run the macro.
    3. It will give a warning about saving work and such. Click OK
    4. Select the range that you want to convert and Click OK.
    5. That's it. Check the work.


    Please Login or Register  to view this content.
    Obviously, this macro is free for personal use, or use at/in your business, but don't sell it or incorporate it into a paid product. Cool? Thanks.
    Attached Files Attached Files
    Last edited by MikeVerDuin; 03-01-2021 at 04:55 PM. Reason: Add a worksheet example

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,523

    Re: Free Macro to convert a column with City State Zip to 3 columns

    Nice to help people this way.
    Would you be able to attach a workbook with examples to work on?

  3. #3
    Registered User
    Join Date
    08-17-2015
    Location
    Grand Haven, Michigan
    MS-Off Ver
    Office 365
    Posts
    2

    Re: Free Macro to convert a column with City State Zip to 3 columns

    Quote Originally Posted by jolivanes View Post
    Nice to help people this way.
    Would you be able to attach a workbook with examples to work on?
    Great idea, I've attached a very simple one now with common problems that I see when getting a file so people can see how it cleans up the file.

+ 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. Equation to Take a Zip code and Convert it to a City and State
    By jkfoxworth in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 11-08-2018, 03:25 PM
  2. Replies: 5
    Last Post: 01-23-2018, 02:26 PM
  3. Replies: 3
    Last Post: 07-11-2017, 12:43 PM
  4. Replies: 0
    Last Post: 08-14-2012, 04:47 PM
  5. Replies: 2
    Last Post: 06-19-2012, 11:30 AM
  6. help seperating city and state. Text to column creates 3 columns
    By Mycotopian in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-31-2007, 02:55 PM
  7. [SOLVED] how do I separate 1 excel column to read city, state, zip columns
    By usndiv in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-26-2006, 05:40 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