+ Reply to Thread
Results 1 to 10 of 10

Thread: splitting address into cells

  1. #1
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    splitting address into cells

    Hey all,

    I have this in one cell:

    901 NE 8 ST HALLANDALE BEACH FL 33009-2626

    Is there a way using a macro, some vbd code, that I can convert address, city, state, and zip to their own columns, where the zip may be 5 or 9 digits. I made an attachment.

    Thanks for any response.
    Attached Files Attached Files
    Last edited by johnmerlino; 09-21-2010 at 10:35 AM.

  2. #2
    Extremely Helpful member
    Join Date
    12-23-2006
    Location
    Belgium
    MS-Off Ver
    XL2003
    Posts
    6,127

    Re: splitting address into cells

    Hi
    can you provide some more examples?
    This way we can see how your strings are organized. Adding a sample sheet would help, noone likes to retype data - Thx
    Quoting entire posts clutters the forum and makes threads hard to read !

    If you are pleased with a member's answer then use the Star icon to rate it

    Click here to see forum rules

  3. #3
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,298

    Re: splitting address into cells

    Hi John,

    With your example data it is hard to come up with a rule to parse out the zip codes. If they are all FL addresses we could key on that.. IE anything after "FL" must be a zip.

    The other problem is that some of the city names are two words. If they were all one word city names we could key on that to parse them out. A larger set of data would allow rules to be attempted to extract your data into an address table.

    hope that helps.

  4. #4
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: splitting address into cells

    They will be either Florida or New York and only cities in Broward County. So I'm thinking of something like this:
    stateArray = Split("FL, NY")
    cityArray = Split("Fort Lauderdale","Sunrise","Oakland Park")
    And then somehow make excel return VALUE! for cells that don't have a city or state containing the indexes of these array.
    Can anyone help with this matter using VBD using macros.
    Thanks.

  5. #5
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Invalid procedure call or argument error when trying to split address info in columns

    Hey all,


    The script below is an attempt to split address, city, state, and zip code into separate columns. Right now each record is in a single column with no delimiters:

    2701 NW 64TH TER*MARGATE FL 33063-1703
    901 NE 8 ST*HALLANDALE BEACH FL 33009-2626
    1840 DEWEY ST UNIT 305*HOLLYWOOD FL 33020
    3049 NE 4 AVE*WILTON MANORS FL 33334-2047
    650 NE 56 CT*OAKLAND PARK FL 33334-3528

    In my Personal.xlsb module in VBAProject, the following script when executed returns an error message "Run-time error '5': Invalid procedure call or argument':

    Sub SplitAddress()
    Dim intloop As Integer, intFindComma As Integer
    Dim strCity As String, strZip As String, strState As String
    Dim strAdd As String, cl As Range, rng As Range
    Dim arrState() As String, loopState As Integer
    Dim arrCity() As String, loopCity As Integer
    
     
    intloop = 1
    arrState = Split("FL, NY")
    arrCity = Split("Fort Lauderdale, Sunrise, Oakland Park, Pompano Beach")
    
     
    With ActiveSheet
     
        Set rng = Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
        
        For loopState = 0 To 1
        
            rng.Replace What:=" " & arrState(loopState) & ". ", Replacement:=" " & arrState(loopState) & " "
            rng.Replace What:=" " & arrState(loopState) & " ", Replacement:=", " & arrState(loopState) & " "
        
        Next
        
        rng.Replace What:=",,", Replacement:=","
        
        Do While .Cells(intloop, 1).Value <> ""
            strAdd = .Cells(intloop, 1).Value
            intFindComma = InStr(strAdd, ",")
            .Cells(intloop, 2).Value = Mid(strAdd, intFindComma + 2, 2)
            .Cells(intloop, 3).Value = Right(strAdd, Len(strAdd) - intFindComma - 4)
            .Cells(intloop, 4).Value = Left(strAdd, intFindComma - 1)
     
            intloop = intloop + 1
        Loop
    
        For loopCity = 0 To 3
        
               rng.Replace What:=" " & arrCity(loopCity) & ". ", Replacement:=" " & arrCity(loopCity) & " "
                rng.Replace What:=" " & arrCity(loopCity) & " ", Replacement:=", " & arrCity(loopCity) & " "
    
            Next
        
            rng.Replace What:=",,", Replacement:=","
    
            Do While .Cells(intloop, 1).Value <> ""
                strAdd = .Cells(intloop, 1).Value
                intFindComma = InStr(strAdd, ",")
                .Cells(intloop, 2).Value = Mid(strAdd, intFindComma + 2, 2)
                .Cells(intloop, 3).Value = Right(strAdd, Len(strAdd) - intFindComma - 4)
                .Cells(intloop, 4).Value = Left(strAdd, intFindComma - 1)
    
                intloop = intloop + 1
            Loop
        
    End With
    End Sub
    Thanks for any response.
    Attached Files Attached Files
    Last edited by johnmerlino; 09-21-2010 at 07:11 PM.

  6. #6
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,298

    Re: splitting address into cells

    Hi John,

    The normal way to do these things is to key on the space between names. Pulling off the zip code is pretty easy. Then if they are only FL or NY that can be done. The problem comes with two word city names. Oakland Park is an example. One way the town is just Park because of the space. The other way 120 South Main Sunrise FL 32145 comes out with Main Sunrise as the city name.

    If we could see the data and work with it there might be a method, but without some real samples it just doesn't fit into a good rule.

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

    Re: Invalid procedure call or argument error when trying to split address info in col

    Is this not for all intents and purposes the same quesrtion as this?

    http://www.excelforum.com/excel-gene...nto-cells.html

  8. #8
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777

    Re: splitting address into cells

    A lookup table of Florida cities would simplify things.

    http://www.stateofflorida.com/Portal....aspx?tabid=34

    EDIT: Threads merged.
    Last edited by shg; 09-21-2010 at 07:32 PM.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: splitting address into cells

    Quote Originally Posted by shg View Post
    A lookup table of Florida cities would simplify things.

    http://www.stateofflorida.com/Portal....aspx?tabid=34

    EDIT: Threads merged.
    Could you elaborate on what you mean by lookup table of florida cities? Thanks.

  10. #10
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: splitting address into cells

    Hey all, I figured out how to get the zip codes and state in their own column. Still stuck on placing city and address in its own column. There is a pattern though. The addresses will end with one of the following: TER, ST, AVE, CT, Blvd, Rd, Hwy, Exp, Pkwy.

    Is there an excel formula that can check for this pattern: TER, ST, AVE, CT, BLVD, RD, HWY, EXP, PKWY.
    Last edited by johnmerlino; 09-22-2010 at 09:43 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0