Hi Ron I ran the code on this data and nothing was changed... No results so
thought I would show the exact data and see what I was missing...I have may
have mislead as to the data having two commas, only 1. Please advise...
Regards patt
E F G
JACKSONVILLE, FL 32224
CHARLESTON, SC 29405
HIALEAH, FL 33016
OCALA, FL 34478-3200
RICHLAND, WA 99352
MIAMI, FL 33138
Well, you wrote that the contents of your cell was "city,state,zip" That's two
commas and no spaces. Your example shows 1 comma and several spaces.
So I would do it differently, and, like in your previous problem, it's easy to
use regular expressions for this kind of problem. Again, you'll need to
properly set up the range. I hard coded it to G1:G100, but there are a variety
of ways to do this, depending on your requirements.
Note there are two lines turning off and then on "screenupdating". Once you
are satisfied that the macro is working correctly, "uncommenting" these lines
so they are active will enable to the macro to run more quickly.
================================================
Option Explicit
Sub ParseCityStateZip()
Dim c As Range, rgToParse As Range
Dim re As Object, mc As Object
Dim i As Long
Set rgToParse = [G1:G100]
'Application.ScreenUpdating = False
Set re = CreateObject("vbscript.regexp")
re.Pattern = "^([^,]+)\W*(\S+)\s+(\S+)$"
For Each c In rgToParse
With c
If re.test(.Text) = True Then
Set mc = re.Execute(.Text)
For i = 0 To 2
.Offset(0, i - 2).NumberFormat = "@"
.Offset(0, i - 2).Value = mc(0).submatches(i)
Next i
End If
End With
Next c
'Application.ScreenUpdating = True
End Sub
==========================================
--ron