IF Functions for Text in Excel 2000

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to separate city, state, zip from 1 cell to 3 by using the IF
function. But I cannot get the IF function to recognize text values, only
numeric. I have already changed the cells format to text, but to no avail.
Any suggestions? Can it be done in excel?
 
if you are using xl2000 or later

Sub Addr()
Dim sStr As String, v As Variant
Dim lCity As Long, zip As String
Dim city As String, state As String
sStr = "Los Angeles, CA 90210"
Range("A1").Value = sStr
v = Split(Range("A1").Value, " ")

lCity = UBound(v) - 2
zip = Trim(v(UBound(v)))
state = Trim(v(UBound(v) - 1))
city = ""
For i = 0 To lCity
city = city & Trim(v(i)) & " "
Next
city = Trim(Replace(city, ",", ""))
Debug.Print city, state, zip

End Sub

for string like

Los Angeles, CA 90210
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top