Extract Text From A String

wallstcheater

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

[TABLE="width: 567"]
<!--StartFragment--> <colgroup><col width="567"> </colgroup><tbody>[TR]
[TD="width: 567"]100 Broadway, Suite 1101 New York, NY?10005 United States[/TD]
[/TR]
[TR]
[TD]Sector 30, NH-8 Gurgaon, Haryana, ?122002[/TD]
[/TR]
[TR]
[TD]61 Broadway 17th floor New York, NY?10006 United States
[TABLE="width: 567"]
<!--StartFragment--> <colgroup><col width="567"> </colgroup><tbody>[TR]
[TD="width: 567"]11 Beacon Street, 3rd Floor Suite 305 Boston, MA?02108 United States[/TD]
[/TR]
[TR]
[TD]88 7th Avenue New York, NY?10109 United States[/TD]
[/TR]
[TR]
[TD]600 Pennsylvania Ave SE Suite 220 Washington, DC?20003 United States[/TD]
[/TR]
[TR]
[TD]1601 Elm Street Suite 3900 Dallas, TX?75201 United States[/TD]
[/TR]
[TR]
[TD]50 Federal Street Suite 600 Boston, MA?02110 United States[/TD]
[/TR]
<!--EndFragment--></tbody>[/TABLE]

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


[/TD]
[/TR]
<!--EndFragment--></tbody>[/TABLE]
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I have thousands of address fields that look like this:

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

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


[/TD]
[/TR]
</TBODY>[/TABLE]
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:

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

I need to separate the street address, city, state, zip and country.
[/TD]
[/TR]
</tbody>[/TABLE]

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
    *****
    *****
    *****
    *****
    *****
    *****
    *****

    <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>
    [TD="bgcolor: #CACACA, align: center"]2[/TD]
    [TD="align: left"]100 Broadway, Suite 1101 New York, NY?10005 United States[/TD]
    [TD="bgcolor: #808000"]100 Broadway, Suite 1101 *[/TD]
    [TD="bgcolor: #808000"]New York[/TD]
    [TD="bgcolor: #808000"]NY[/TD]
    [TD="bgcolor: #808000, align: right"]10005[/TD]
    [TD="bgcolor: #808000"]United States[/TD]

    [TD="bgcolor: #CACACA, align: center"]3[/TD]
    [TD="align: left"]Sector 30, NH-8 Gurgaon, Haryana, ?122002[/TD]

    [TD="bgcolor: #CACACA, align: center"]4[/TD]
    [TD="align: left"]61 Broadway 17th floor New York, NY?10006 United States[/TD]

    [TD="bgcolor: #CACACA, align: center"]5[/TD]
    [TD="align: left"]11 Beacon Street, 3rd Floor Suite 305 Boston, MA?02108 United States[/TD]

    [TD="bgcolor: #CACACA, align: center"]6[/TD]
    [TD="align: left"]88 7th Avenue New York, NY?10109 United States[/TD]

    [TD="bgcolor: #CACACA, align: center"]7[/TD]
    [TD="align: left"]600 Pennsylvania Ave SE Suite 220 Washington, DC?20003 United States[/TD]

    [TD="bgcolor: #CACACA, align: center"]8[/TD]
    [TD="align: left"]1601 Elm Street Suite 3900 Dallas, TX?75201 United States[/TD]

    [TD="bgcolor: #CACACA, align: center"]9[/TD]
    [TD="align: left"]50 Federal Street Suite 600 Boston, MA?02110 United States[/TD]

    </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,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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