Extract State Abbreviation with No Commas - HELP!

drockdamian

New Member
Joined
Dec 13, 2021
Messages
11
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello All,

I need help extracting the state abbreviation and zip code from this single string address line. There are two space in between the state abbreviation and the zip code; only one space between the end of zip code and country. Here is a sample.

8270 Petaluma Hill Rd Attn: Broc Croll Penngrove CA 94951-9747 USA
1105 Arden Rd Pasadena CA 91106-4005 USA
2010 Wentworth Dr Billings MT 59105-3535 USA
3372 S 7780 W Magna UT 84044-2041 USA
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Welcome to the MrExcel board!

See if this is what you want.

21 12 14.xlsm
ABC
1StateZip
28270 Petaluma Hill Rd Attn: Broc Croll Penngrove CA 94951-9747 USACA94951-9747
31105 Arden Rd Pasadena CA 91106-4005 USACA91106-4005
42010 Wentworth Dr Billings MT 59105-3535 USAMT59105-3535
53372 S 7780 W Magna UT 84044-2041 USAUT84044-2041
State and Zip
Cell Formulas
RangeFormula
B2:B5B2=TRIM(LEFT(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),400),100))
C2:C5C2=TRIM(LEFT(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),200),100))
 
Upvote 0
Solution
Wow! It worked, thank you so much! My formula was definitely not set it up like that. I'll have to study what each means. Thanks again Peter.
Welcome to the MrExcel board!

See if this is what you want.

21 12 14.xlsm
ABC
1StateZip
28270 Petaluma Hill Rd Attn: Broc Croll Penngrove CA 94951-9747 USACA94951-9747
31105 Arden Rd Pasadena CA 91106-4005 USACA91106-4005
42010 Wentworth Dr Billings MT 59105-3535 USAMT59105-3535
53372 S 7780 W Magna UT 84044-2041 USAUT84044-2041
State and Zip
Cell Formulas
RangeFormula
B2:B5B2=TRIM(LEFT(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),400),100))
C2:C5C2=TRIM(LEFT(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),200),100))
 
Upvote 0
You're welcome. Thanks for the follow-up. :)

If the double space after the state is the only double space in the text, then you could also use this for state
Excel Formula:
=MID(A2,FIND("  ",A2)+2,10)

.. and if all the Zip extractions are 10 characters long (as well as the only double space mentioned above) ..
Excel Formula:
=MID(A2,FIND("  ",A2)+2,10)
 
Upvote 0
You're welcome. Thanks for the follow-up. :)

If the double space after the state is the only double space in the text, then you could also use this for state
Excel Formula:
=MID(A2,FIND("  ",A2)+2,10)

.. and if all the Zip extractions are 10 characters long (as well as the only double space mentioned above) ..
Excel Formula:
=MID(A2,FIND("  ",A2)+2,10)
Thanks Peter, I really appreciate it. How would I go about learning the first method?
 
Upvote 0
what does each part of the formula mean
SUBSTITUTE(A2," ",REPT(" ",100))
This puts 100 spaces everywhere there is currently a space character.
At the right side of the original string that will put 100 spaces between Zip & Country, 200 spaces between State and Zip, 100 spaces between City and State.

If you now take the RIGHT hand 400 characters of that you will get, working from the RIGHT, the Country, the 100 spaces between Zip & Country, the Zip, the 200 spaces between State & Zip, the State and some only of the 100 spaces between City and State.

If you now take the LEFT hand 100 characters of that you will get, working from the LEFT, the some only of the 100 spaces between City & State mentioned above, the State and some only of the 200 spaces between Sate & Zip.
TRIM then removes all the surrounding spaces (blue and red mentioned above) leaving just the State.

The other formula works in a similar manner.
 
Upvote 0
Amazing...thank you so much for your time and effort on this topic. It is truly appreciated. I can't thank you enough. I hope you have a great holiday season!
 
Upvote 0
You're welcome. Thanks for the follow-up.
.. and your kind words. All the best to you too. :)
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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