Formula for pulling State from Cell

Craig92604

Well-known Member
Joined
Nov 7, 2002
Messages
505
I put together this formula to pull the state from a cell that contains City, State and Zip

=MID(B19,FIND(" ",B19,1),3)

Works fine for when the City is One word but when it is two words it doesn't work.

This formula works if there is two word city=MID(B19,FIND(" ",B19,FIND(" ",B19,C19+1)),3)

What I am looking for is a formula to count the number of spaces in a cell. Then I could build a nested if statment to handle cells with both 1 and two word cities.

PS- There is not a comma after the city
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

NBVC

Well-known Member
Joined
Aug 31, 2005
Messages
5,828
=LEN(B19)-LEN(SUBSTITUTE(B19," ","")) will tell you how many spaces in B19
 

Craig92604

Well-known Member
Joined
Nov 7, 2002
Messages
505
Worked Like a Charm! Thanks Andrew and NBVC!

=IF(LEN(B19)-LEN(SUBSTITUTE(B19," ",""))>2,MID(B19,FIND(" ",B19,FIND(" ",B19,FIND(" ",B19,1)+1)),3),MID(B19,FIND(" ",B19,1),3)
)
 

Forum statistics

Threads
1,141,224
Messages
5,705,116
Members
421,378
Latest member
CarlosDuran

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
Top