Extract City and State from address

scojax22

New Member
Joined
Apr 1, 2014
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I have a database of full addresses, including city and state in 1 cell. I want to add two new columns for city and state, and need a formula for each - I am using Left(Find",") to extract the address and Right(5) for the zip - but the city and state are giving me problems.

Any help would be great.

Ex: 101 Main Street, Cherry Hill, NJ 08510
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Welcome to the board

With the address in A2

Street: =LEFT(A2,FIND(",",A2)-1)
City: =TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",255)),255,255))
State: =MID(A2,LEN(A2)-7,2)
Zip: =RIGHT(A2,5)
 
Last edited:
Upvote 0
Awesome. No idea what the City formula did, but it works like a charm!
 
Upvote 0
City: =TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",255)),255,255))
Awesome. No idea what the City formula did, but it works like a charm!
There could be one possible problem with Jonmo1's City formula depending on what is allowed in the address part of your data. If suite or apartment numbers are allowed, they usually appear comma-separated from the address proper, something like this...

101 Main Street, Apt. 3B, Cherry Hill, NJ 08510

If your database allows that, then Jonmo1's formula will return "Apt. 3B" instead of "Cherry Hill". Here is a formula that should work with or without suite/apartment numbers...

=TRIM(LEFT(RIGHT(SUBSTITUTE(A2,",",REPT(" ",250)),500),250))
 
Upvote 0
There could be one possible problem with Jonmo1's City formula depending on what is allowed in the address part of your data. If suite or apartment numbers are allowed, they usually appear comma-separated from the address proper, something like this...

101 Main Street, Apt. 3B, Cherry Hill, NJ 08510

If your database allows that, then Jonmo1's formula will return "Apt. 3B" instead of "Cherry Hill". Here is a formula that should work with or without suite/apartment numbers...

=TRIM(LEFT(RIGHT(SUBSTITUTE(A2,",",REPT(" ",250)),500),250))
This is on the track of what I'm looking for, but how do I make this work if my data contains a comma between the state and the postcode?

Examples:


81 Ghostgum Bvd, Banksia Grove, WA, 6031
150 Camborne Pwy, Butler, WA, 6036
Cnr Yanchep Beach Rd & Marmion Ave, Yanchep, WA, 6035
Centro Stirling, 54 Sanford St, Geraldton, WA, 6530
Lakeside Joondalup Shop. Ctr, 420 Joondalup Dr, Joondalup, WA, 6027
19 Neerabup Road, Clarkson, WA, 6030
Stirling Central Shop. Ctr, 478 Wanneroo Rd, Westminster, WA, 6061
Dog Swamp Shop. Ctr, 6 Wanneroo Rd, Yokine, WA, 6060
Glenview MarketPl, Cnr Hamelin And Bellefin Drs, Ballajura, WA, 6066
360-366 Grand Promenade, Dianella, WA, 6059
 
Upvote 0
Does ALL of your data have a comma between the state and post code (or only some of it)?
 
Upvote 0
Have you tried FLASH FILL? Not perfect but you might get close.
Is it always WA?

Book3
ABC
181 Ghostgum Bvd, Banksia Grove, WA, 6031Banksia GroveWA
2150 Camborne Pwy, Butler, WA, 6036ButlerWA
3Cnr Yanchep Beach Rd & Marmion Ave, Yanchep, WA, 6035YanchepWA
4Centro Stirling, 54 Sanford St, Geraldton, WA, 6530GeraldtonWA
5Lakeside Joondalup Shop. Ctr, 420 Joondalup Dr, Joondalup, WA, 6027JoondalupWA
619 Neerabup Road, Clarkson, WA, 6030ClarksonWA
7Stirling Central Shop. Ctr, 478 Wanneroo Rd, Westminster, WA, 6061WestminsterWA
8Dog Swamp Shop. Ctr, 6 Wanneroo Rd, Yokine, WA, 6060YokineWA
9Glenview MarketPl, Cnr Hamelin And Bellefin Drs, Ballajura, WA, 6066BallajuraWA
10360-366 Grand Promenade, Dianella, WA, 6059DianellaWA
Sheet1
Cell Formulas
RangeFormula
B1:B10B1=TEXTAFTER(TEXTBEFORE(A1,", WA"),", ",-1)
C1:C10C1=LEFT(RIGHT(A1,8),2)
 
Last edited:
Upvote 0
Or maybe:

Book3
ABC
181 Ghostgum Bvd, Banksia Grove, WA, 6031Banksia GroveWA
2150 Camborne Pwy, Butler, WA, 6036ButlerWA
3Cnr Yanchep Beach Rd & Marmion Ave, Yanchep, WA, 6035YanchepWA
4Centro Stirling, 54 Sanford St, Geraldton, WA, 6530GeraldtonWA
5Lakeside Joondalup Shop. Ctr, 420 Joondalup Dr, Joondalup, WA, 6027JoondalupWA
619 Neerabup Road, Clarkson, WA, 6030ClarksonWA
7Stirling Central Shop. Ctr, 478 Wanneroo Rd, Westminster, WA, 6061WestminsterWA
8Dog Swamp Shop. Ctr, 6 Wanneroo Rd, Yokine, WA, 6060YokineWA
9Glenview MarketPl, Cnr Hamelin And Bellefin Drs, Ballajura, WA, 6066BallajuraWA
10360-366 Grand Promenade, Dianella, WA, 6059DianellaWA
11111 Main Street, Newark, NJ, 12345NewarkNJ
Sheet1
Cell Formulas
RangeFormula
B1:B11B1=TEXTAFTER(TEXTBEFORE(A1,", ",-2),", ",-1)
C1:C11C1=LEFT(TEXTAFTER(A1,", ",-2),2)
[XD]=TEXTAFTER(TEXTBEFORE(A1,", ",-2),", ",-1)[/XD][/XR][/RANGE]
 
Upvote 0
TRY. A2:A8 data.
Formula in B2.
Excel Formula:
=TEXTSPLIT(TEXTJOIN(",",0,BYROW(A2:A8,LAMBDA(ro,LET(a,TEXTSPLIT(ro,","),b,TEXTSPLIT(INDEX(a,3)," "),INDEX(a,2)&"_"&INDEX(b,2))))),"_",",")
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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