+ Reply to Thread
Results 1 to 35 of 35

How to Extract the City and State from a Address Column not Separated by a Comma?

  1. #1
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    How to Extract the City and State from a Address Column not Separated by a Comma?

    Hello,

    I need to extract the City and the State to their own columns to the right of Column BK, i.e. BL and BM with the State being capitalized (sometimes in the source file, the State is in lower case).
    My contact list has the City and State combined under Column BK. They are not separated by a comma. See following format:

    Lake View Terrace ca
    Burbank ca
    Sherman Oaks Ca

    Thanks you for your help.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Is State always the two letter abbreviation...?

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Try this for starters to check results are correct.
    Please Login or Register  to view this content.
    Last edited by bakerman2; 06-10-2016 at 03:49 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Hello, the State is always the 2 letter abbreviation. I ran the code offered by bakerman 2. I received an error message, Subscript out of range (Error 9) for the line, x1 = UCase(a(UBound(a))).

    Here's what my code looks like with the range inserted.

    S
    Please Login or Register  to view this content.
    Last edited by SeaTiger; 06-10-2016 at 01:56 PM.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Please use code tags when posting code (select code and click #)
    As for your question.
    Please Login or Register  to view this content.

  6. #6
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Enter formula in B1 and pull it to C1 and then down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v A B C
    1 Lake View Terrace ca Lake View Terrac ca
    2 Burbank ca Burban ca
    3 Sherman Oaks Ca Sherman Oak Ca
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  7. #7
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Hello bakerman2,

    I'm still receiving the Subscript out of range (Error 9) for the line,
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Hello Alkey, thanks for your formula. How can I correct the State so that both letters are capitalized?

  9. #9
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Here is a modified formula that will capitalize states
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v A B C
    1 Lake View Terrace ca Lake View Terrace CA
    2 Burbank ca Burbank CA
    3 Sherman Oaks Ca Sherman Oaks CA

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    I just assumed it was a continuous range without empty cells in between.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Many thanks for you help. Here's one that I found that will create the columns BL and BM. You will need to change your work sheet name accordingly.

    Please Login or Register  to view this content.

  12. #12
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Thanks for the rep. One observation though.
    It's never a good idea to loop through cells on a worksheet. It slows down execution because of all that sheet interaction.
    My code reads the entire range in memory, splits the values and writes results in 1 time back to your sheet. So 2 actions while you perform 200.
    So my code takes less then 1/3 of the time you need.

  13. #13
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Hello Bakerman2,

    Thanks for the additional info. Can you add code to your formula so that is will create the 2 columns, BL & BM that the data extracts to? Thanks!

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

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    @ SeaTiger.
    Your code in Post #11 does not capitalize as you yourself requested in Post #8 and it also stops at the first empty cell.
    This could be what you want but it sounded like you might have empty rows (Post #10).

  15. #15
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Hello Jolivanes, good catch....your right! I checked the list again after reading your post and the code in post # 11 it did not capitalze all the states. It turns our most of them were all ready capitalbized. Well, I welcome an updated code with that function.

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

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Please Login or Register  to view this content.
    should do it.

    BTW, if there are empty cells in your range, I would loop, if that is what you want to do, with something like this.
    The looping might be easier to understand but I would stick with bakerman2's code though.

    Change the cell references as required.
    Please Login or Register  to view this content.
    Last edited by jolivanes; 06-11-2016 at 04:52 PM. Reason: add info

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

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Here is another loop you won't be using.
    I would not give you all this if it wasn't raining cats and dogs out here and I could mow the lawn.
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Hello, I just run bakerman2's code again per post #10. It does everything that I requested. It created BL, BM columns witht he state capitalzied. Thanks again for everyone's comments and help.

  19. #19
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Of course.

  20. #20
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Hello bakerman2, my apologies, but after checking closer, what your code does is override the data that is all ready in BL & BM which I do not want to do. I should have disclosed that there was all ready data in thesee 2 columns. So, would you mind adding that code so that the City and State are extracted to BL, BK, with the data in the columns to the right of them get shifted over accordingly. Again if possible, the headings for the new columns would be tor_maling_city1 and tor_mailing_state1. Again, I am deeply grately for you help.

  21. #21
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Please post example file of how your columns look like now and how you want it to be afterwards. Remember to desensitize information.

  22. #22
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    current file:
    1st row is the Column reference, 2nd row is the Column Name, and balance of rows are the data. The worksheet columns range is A:DE without the 2 new colums added, A:DG with. In the desired file, thus Column BK would not change and BL now becomes BN because it shifted over.
    BK BL
    tor_mailing_city tor_mailing_zip
    Culver City Ca 90230
    Glendale Ca 91201
    Glendale Ca 91206
    La Mirada Ca 90638

    desired file:

    BL BM BN
    tor_mailing_city1 tor_mailing_state1 tor_mailing_zip
    Culver City CA 90230
    Glendale CA 91201
    Glendale CA 91206
    La Mirada CA 90638
    Last edited by SeaTiger; 06-11-2016 at 09:07 PM. Reason: I made a mistake in the column references and formating info.

  23. #23
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Try this.
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    I'm realizing that I need to be more clearer in my communication. Thank you for your understanding. I'm in the learning curve. Again, thank you for your efforts.

    What the formula does in post # 23 is override the data in the pre-existing columns BM & BN so that the "trustee_name" and "tee_st" are replaced with the extracted data from BK "tor_mailing_city1" and "tor_mailing_state1" respectively. We do not want to lose this data. So, I re-did the desired file format, hoping that you understand what we need.

    This is the current file format:

    BK BL BM BN
    tor_mailing_city tor_mailing_zip trustee_name tee_st
    Los Angeles Ca 90230 Belgium Bank 1000 EXCEL RD


    This is the desired file format whereas BK = no change, BL= is the city extracted from BK, BM = is the state abbreviation extracted from BK, BN = the zip code extracted from BL, BO= the trustee name extracted from BM and, BP = the turstee street extracted from BN. There is no change in the data in the balance of the columns (BP:DD) other than their columns are updated to be sequential in order:

    BK BL BM BN BO BP
    tor_mailing_city tor_mailing_city1 tor_mailing_state1 tor_mailing_zip trustee_name tee_st
    Los Angeles ca Los Angeles CA 90230 Belgium Bank 1000 EXCEL RD
    Last edited by SeaTiger; 06-12-2016 at 12:33 PM. Reason: corrected html code

  25. #25
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    So if I understand correctly by inserting 2 columns after BK and putting the split in those 2 new columns you're problems solved ?
    Please Login or Register  to view this content.
    Last edited by bakerman2; 06-13-2016 at 12:44 AM.

  26. #26
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Almost got it Buddy...however, now BN="tee_st" instead of "tor_mailing_zip"(it needs to be extracted from BL; see my post #24). BO and BP are fine as well as balance of columns

  27. #27
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Post example file with the formulas you use to extract mailing_zip, trustee_name & tee_st.

  28. #28
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Here is an example of the file format as reference without any code so that you can test your code.
    Attached Files Attached Files

  29. #29
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Your profile doesn't say, but if you have Excel 2013 there is a feature called Flash Fill in the Data ribbon.

    Type one example of each field as desired (including case) as below. Then with column C the active column apply Flash Fill. Next do column D and E in succession. A fly-out will prompt you for accept / undo. This worked at my end.

    Row\Col
    A
    B
    C
    D
    E
    1
    Culver City Ca
    90230
    Culver City CA
    90230
    2
    Glendale Ca
    91201
    Glendale CA
    91201
    3
    Glendale Ca
    91206
    Glendale CA
    91206
    4
    La Mirada Ca
    90638
    La Mirada CA
    90638
    Dave

  30. #30
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    See revised code in post#25.

  31. #31
    Registered User
    Join Date
    12-16-2008
    Location
    Los Angeles
    Posts
    29

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Code in Post # 25 works superb!!! Well done bakerman2. Tysm for your time and consideration. That goes for everyone else that provided help.

    BTW, I have Excel 2010 so don't believe I've seen Flash Fill so post # 29 solution is not available to me.

  32. #32
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    You're very welcome.
    Sorry for the delay but was a bit confused about layout. Once visualized it was a piece of cake.

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

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    @bakerman2
    Re: "Piece of cake"
    Vlaamse vlaai?

  34. #34
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?


  35. #35
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: How to Extract the City and State from a Address Column not Separated by a Comma?

    Quote Originally Posted by SeaTiger View Post
    Code in Post # 25 works superb!!! Well done bakerman2. Tysm for your time and consideration. That goes for everyone else that provided help.

    BTW, I have Excel 2010 so don't believe I've seen Flash Fill so post # 29 solution is not available to me.

    _______________

+ 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. Pulling company name, street address, city, state, and zip from address
    By UNREAL2K4 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-13-2015, 12:53 PM
  2. Separating Street Address City State Zip that only contain spaces
    By tp5887 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-27-2015, 02:52 PM
  3. City, State Segregation from Address
    By Mohanmoni in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-14-2015, 04:49 PM
  4. [SOLVED] Split Address In City & State Wise
    By Mohanmoni in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-31-2015, 08:14 PM
  5. What is the formula to add a comma between city and state
    By lilabee in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-11-2012, 12:00 PM
  6. How to get rid of the city and state in the address?
    By excel1212 in forum Excel General
    Replies: 2
    Last Post: 09-08-2012, 05:30 PM
  7. Replies: 2
    Last Post: 02-02-2012, 12:47 AM

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