+ Reply to Thread
Results 1 to 7 of 7

Extract UK address into seperate cells

  1. #1
    Registered User
    Join Date
    09-03-2010
    Location
    London, England
    MS-Off Ver
    MS EXCEL 365 (v. 2111)
    Posts
    41

    Extract UK address into seperate cells

    I hope someone can help me.

    I have c 500 address which i need to sepearte into sepearte cells for the purpose of a mail merge.

    I have attached an excel spreadsheet with all the addresses in and have managed to extract the first line of the address using the LEFT function.

    I reckon i can work out how to get the postocde but dont know how to seperate the middle (towns, counties) etc.

    Hope you can help.
    Attached Files Attached Files

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Extract UK address into seperate cells

    Try this in C1, copy down:

    =LEFT(A1,FIND(",",A1,1)-1)
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    09-03-2010
    Location
    London, England
    MS-Off Ver
    MS EXCEL 365 (v. 2111)
    Posts
    41

    Re: Extract UK address into seperate cells

    Thanks davegugg,

    This is the forumla i used to extract the first line of the address (which i already have). I am trying to find a formula which would let me extract the second line, town, county and post code. So for example, C1 = 32 Oak Mead, D1 = Farncombe, E1 = Godalming, F1 = GU7 3RJ.

    I am sure there is a simple way to do this because i've managed it before but i just cant work it out!

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Extract UK address into seperate cells

    Try, in C1:

    =TRIM(SUBSTITUTE(SUBSTITUTE(A1,B1&",",""),F1,""))

    You can hide this column

    in D1:

    =IFERROR(LEFT(C1,FIND(",",C1)-1),"")

    in E1:

    =IFERROR(TRIM(SUBSTITUTE(MID(C1,FIND(",",C1)+1,255),",","")),"")

    in F1:

    =TRIM(MID(A1,FIND("^^",SUBSTITUTE(A1," ","^^",(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-1))),100))

    each copied down.

    or if you don't want the hidden comma, then in C1:

    =IFERROR(LEFT(TRIM(SUBSTITUTE(SUBSTITUTE(A1,B1&",",""),E1,"")),FIND(",",TRIM(SUBSTITUTE(SUBSTITUTE(A1,B1&",",""),E1,"")))-1),"")

    in D1:

    =IFERROR(TRIM(SUBSTITUTE(MID(TRIM(SUBSTITUTE(SUBSTITUTE(A1,B1&",",""),E1,"")),FIND(",",TRIM(SUBSTITUTE(SUBSTITUTE(A1,B1&",",""),E1,"")))+1,255),",","")),"")

    in E1:

    =TRIM(MID(A1,FIND("^^",SUBSTITUTE(A1," ","^^",(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-1))),100))
    Last edited by NBVC; 10-04-2011 at 02:00 PM. Reason: added option for no helper column
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  5. #5
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Extract UK address into seperate cells

    I see NBVC has a solution, but here's how I would have evolved my original response to provide a solution:

    In C1: =LEFT(A1,FIND(",",A1,1)-1)

    In D1: =IF(ISERROR(MID(A1,LEN(C1)+3,FIND(",",A1,LEN(C1)+3)-(LEN(C1)+3))),RIGHT(A1,LEN(A1)-LEN(C1)-2),MID(A1,LEN(C1)+3,FIND(",",A1,LEN(C1)+3)-(LEN(C1)+3)))

    In E1: =IF(ISERROR(MID(A1,LEN(D1)+LEN(C1)+5,FIND(",",RIGHT(A1,LEN(A1)-(LEN(D1)+LEN(C1)+5))))),"",MID(A1,LEN(D1)+LEN(C1)+5,FIND(",",RIGHT(A1,LEN(A1)-(LEN(D1)+LEN(C1)+5)))))

    In F1: =IF(ISERROR(RIGHT(A1,LEN(A1)-FIND(",",A1,(LEN(C1)+LEN(D1)+LEN(E1)))-1)),"",IF(E1="","",(RIGHT(A1,LEN(A1)-FIND(",",A1,(LEN(C1)+LEN(D1)+LEN(E1)))-1))))

    And the moral of this thread is ALWAYS separate your data to begin with when you have the option. It's much easier to join data from different columns than to separate a single column into different pieces (street address, city, zip, etc.)

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Extract UK address into seperate cells

    There is a bit more to your problem than meets the eye due to inconsistancies in your data.

    Try this
    1/. Use Text to Columns to spilt the initial string in "Sheet1" Column A
    Select Column A then Data > Text to Columns Choose:= Delimited ... Next >
    Check:= Comma ... Next>
    In the Destination Field Change $A$1 to $B$1 ... Finish

    2/. With "Sheet1"
    In I1
    Please Login or Register  to view this content.
    In J1
    Please Login or Register  to view this content.
    Drag/Fill both Down

    Note:= There is no easy way to tell what is a county and what is a city/town, so column I is a mixture of towns/cities and counties.

    3/ With "Sheet2"
    In A1
    Please Login or Register  to view this content.
    Drag Across to Column G Then Down

    In H1
    Please Login or Register  to view this content.
    Drag Across to Column J Then Down

    4/. You can now Copy "Sheet2" and Paste Values to wherever.

    This is not perfect, but I think it's a fair way towards getting the result you need.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Extract UK address into seperate cells

    For some reason the Go Advanced button seems to be broken when trying to edit a post, so I can't change the attachment in the previous post

    I have added NBVCs' solution to this workbook so you can compare the results.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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