+ Reply to Thread
Results 1 to 13 of 13

Separate Zip Code from Address

  1. #1
    Registered User
    Join Date
    10-14-2011
    Location
    Utah
    MS-Off Ver
    Excel 2007
    Posts
    25

    Separate Zip Code from Address

    I have a spreadsheet containing thousands of addresses, and I need to separate the zip code from the address. Each address is in its own cell, and the only divider is spaces (sometimes two spaces). I attached an example of what some entries look like. Is it possible single out the zip code? addresslist example.xlsx

  2. #2
    Registered User
    Join Date
    01-16-2013
    Location
    Oklahoma City, OK
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Separate Zip Code from Address

    I'd do a find and replace and just remove the Country all together so the data has the zip code at the end.

    After that, I would use the =RIGHT(cell,5) formula in the cell right next to the address listing to get the zip code separated out.

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Separate Zip Code from Address

    Could you provide a some more realistic examples (dummy) to work with please, and where is this data coming from?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Registered User
    Join Date
    10-14-2011
    Location
    Utah
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Separate Zip Code from Address

    Thanks for the suggestion jemmers. Two problems with that approach are there are hundreds of countries, and some zips are formatted "zip+4." Here's a more realistic example with dummy addresses. addresslist example2.xlsx The list comes from internal software without the capability of separating the address into different columns.

    I could also accomplish what I need to by separating the state and country
    Last edited by geddes_3; 12-12-2013 at 07:19 PM.

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Separate Zip Code from Address

    This works for most, but does not work if there is more than 1 word (space) after the number
    =MID(TRIM(A2),SEARCH("xx",SUBSTITUTE(TRIM(A2)," ","xx",LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))-IF(ISNUMBER(RIGHT(A2,3)*1),0,1)),1)+1,5+IF(ISNUMBER(SEARCH("-",A2,1)),5,0))

  6. #6
    Registered User
    Join Date
    10-14-2011
    Location
    Utah
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Separate Zip Code from Address

    Thanks FDibbins. That makes my data much more manageable Can the country and state be separated as well using something similar?

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Separate Zip Code from Address

    This will pull the country from most of the entries (it pulls the last word after the last space)...
    =IF(ISNUMBER(RIGHT(A2,3)*1),"",MID(SUBSTITUTE(TRIM(A2)," ","xx",LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))),SEARCH("xx",SUBSTITUTE(TRIM(A2)," ","xx",LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))),1)+2,99))

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Separate Zip Code from Address

    If you have that very 1st formula I gave you in column C (adjust as needed), you can use this to pull out the state (again, it will not work with all)...
    =MID(A2,SEARCH(C2,A2,1)-3,2)

  9. #9
    Registered User
    Join Date
    10-14-2011
    Location
    Utah
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Separate Zip Code from Address

    Thank you! It may not be a perfect solution, but it's probably the best one for managing this sloppy data

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Separate Zip Code from Address

    Happy to help and thanks for the feedback

  11. #11
    Registered User
    Join Date
    05-17-2013
    Location
    Guatemala
    MS-Off Ver
    Excel 2013
    Posts
    1

    Re: Separate Zip Code from Address

    FDibbins, What does the Search("xx" does exactly and what are the substitutes for?

  12. #12
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Separate Zip Code from Address

    I use that as a "place holder". It is pretty much a unique text string that is easy to find. To keep the explaination simple, I will ignore those entries that did not have the zip code at the end.

    I counted the lenth of the string using =len(). Then I used substitute() to remove the spaces, and thenb count the length of that modified string. That tells me how many spaces there are, and I replace the last space with "xx" - so I know where that space is. The seach then looks for the "xx", to find where the numbers start

    Make sense? Clear as mud?

  13. #13
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    Office 2021
    Posts
    2,237

    Re: Separate Zip Code from Address

    May be this also,

    B2: for ZIP Codes,

    =TRIM(RIGHT(SUBSTITUTE(LEFT(A2,MATCH(10,INDEX(MID(A2,ROW(INDEX(A:A,1):INDEX(A:A,LEN(A2))),1)+0,0)))," ",REPT(" ",20)),20))

    C2: for States

    =TRIM(RIGHT(SUBSTITUTE(LEFT(A2,FIND(B2,A2)-2)," ",REPT(" ",10)),10))

    D2: for Country

    =TRIM(MID(A2,FIND(B2,A2)+LEN(B2),999))

    Then B2:D2 & copy down.
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

+ 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. Converting a complete, single column address into separate columns for ADDRESS, CITY, ST,
    By jeffrogerssn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2012, 10:34 AM
  2. Replies: 10
    Last Post: 03-08-2012, 12:31 PM
  3. Separate out an address
    By thillis in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-14-2009, 08:12 PM
  4. Separate address
    By xion.hack in forum Excel General
    Replies: 4
    Last Post: 10-07-2009, 08:19 AM
  5. separate name and address
    By Aaron in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-17-2005, 02:25 PM

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