Extract Text From A String

wallstcheater

New Member
Joined
Sep 13, 2013
Messages
3
I have thousands of address fields that look like this:

100 Broadway, Suite 1101 New York, NY?10005 United States
Sector 30, NH-8 Gurgaon, Haryana, ?122002
61 Broadway 17th floor New York, NY?10006 United States
11 Beacon Street, 3rd Floor Suite 305 Boston, MA?02108 United States
88 7th Avenue New York, NY?10109 United States
600 Pennsylvania Ave SE Suite 220 Washington, DC?20003 United States
1601 Elm Street Suite 3900 Dallas, TX?75201 United States
50 Federal Street Suite 600 Boston, MA?02110 United States

<!--StartFragment--> <colgroup><col width="567"> </colgroup><tbody>
<!--EndFragment--></tbody>

I need to separate the street address, city, state, zip and country.



<!--StartFragment--> <colgroup><col width="567"> </colgroup><tbody>
<!--EndFragment--></tbody>
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I have thousands of address fields that look like this:

100 Broadway, Suite 1101 New York, NY?10005 United States
Sector 30, NH-8 Gurgaon, Haryana, ?122002
61 Broadway 17th floor New York, NY?10006 United States
11 Beacon Street, 3rd Floor Suite 305 Boston, MA?02108 United States
88 7th Avenue New York, NY?10109 United States
600 Pennsylvania Ave SE Suite 220 Washington, DC?20003 United States
1601 Elm Street Suite 3900 Dallas, TX?75201 United States
50 Federal Street Suite 600 Boston, MA?02110 United States

<TBODY>
</TBODY>

I need to separate the street address, city, state, zip and country.



<TBODY>
</TBODY>
There is no reliable way to pull the city out of that text because there is no delimiter (comma) between the street and the city... without a full and comprehensive list of possible cities, there is no way for a formula (or VB code for that matter) to know if the city is made up of one, two or three words.
 
Upvote 0
I have thousands of address fields that look like this:

100 Broadway, Suite 1101 New York, NY?10005 United States
Sector 30, NH-8 Gurgaon, Haryana, ?122002

61 Broadway 17th floor New York, NY?10006 United States
11 Beacon Street, 3rd Floor Suite 305 Boston, MA?02108 United States
88 7th Avenue New York, NY?10109 United States
600 Pennsylvania Ave SE Suite 220 Washington, DC?20003 United States
1601 Elm Street Suite 3900 Dallas, TX?75201 United States
50 Federal Street Suite 600 Boston, MA?02110 United States

<tbody>
</tbody>

I need to separate the street address, city, state, zip and country.

<tbody>
</tbody>

Mr. Rothstein is correct, but I used a different approach that might solve your issue for most us cities

  1. Create a dictionary with possible cities or defined name with US cities. Google a list of US cities this site List of United States cities by population - Wikipedia, the free encyclopedia it took me 10 min top create the city dictionary with 278 rows
  2. Notes :that CityUS has 278 cities you can add more cities if you see that they are going to be appearing but remember to increase the range of the formula, otherwise the lookup will not work. Use CTL+SHIFT+ENTER to enter the formula in column C
  3. They still will be some inconsistencies and you will need to validate the final data set row by row typing any missing data. <title>Excel Jeanie HTML</title>


    <!-- ######### Start Created Html Code To Copy ########## -->


    String

    *ABCDEF
    2100 Broadway, Suite 1101 New York, NY?10005 United States100 Broadway, Suite 1101 *New YorkNY10005United States
    3Sector 30, NH-8 Gurgaon, Haryana, ?122002*****
    461 Broadway 17th floor New York, NY?10006 United States*****
    511 Beacon Street, 3rd Floor Suite 305 Boston, MA?02108 United States*****
    688 7th Avenue New York, NY?10109 United States*****
    7600 Pennsylvania Ave SE Suite 220 Washington, DC?20003 United States*****
    81601 Elm Street Suite 3900 Dallas, TX?75201 United States*****
    950 Federal Street Suite 600 Boston, MA?02110 United States*****

    <colgroup><col style="width: 30px; font-weight: bold;"><col style="width: 495px;"><col style="width: 282px;"><col style="width: 169px;"><col style="width: 64px;"><col style="width: 64px;"><col style="width: 90px;"></colgroup><tbody>
    </tbody>

    Spreadsheet Formulas
    CellFormula
    B2=SUBSTITUTE(LEFT(A2,FIND("?",A2,1)-3),C2&",","")
    C2{=IF(SUMPRODUCT(IFERROR(--(FIND(CityUS,A2,1)>0),0),ROW($A$1:$A$278))=0,"",INDEX(CityUS,SUMPRODUCT(IFERROR(--(FIND(CityUS,A2,1)>0),0),ROW($A$1:$A$278)),))}
    D2=MID(A2,FIND("?",A2,1)-2,2)
    E2=MID(A2,FIND("?",A2,1)+1,5)
    F2=MID(A2,FIND("?",A2,1)+7,LEN(A2)-FIND("?",A2,1)+7)

    <tbody>
    </tbody>
    Formula Array:
    Produce enclosing
    { } by entering
    formula with CTRL+SHIFT+ENTER!

    <tbody>
    </tbody>


    Excel tables to the web >> Excel Jeanie HTML 4


     

     
    This is a link to the dictionary http://sdrv.ms/1827ncC
 
Last edited:
Upvote 0
There is no reliable way to pull the city out of that text because there is no delimiter (comma) between the street and the city... without a full and comprehensive list of possible cities, there is no way for a formula (or VB code for that matter) to know if the city is made up of one, two or three words.

Thank you for the response. At first it seems like a very easy problem. I searched the forum and tried a variety of solutions, but nothing seemed to work that well. Maybe I should pass it off to a co-worker and claim that I am too busy!
 
Upvote 0

Forum statistics

Threads
1,215,528
Messages
6,125,342
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top