Sub TestMindy9805()
'
Dim CityLength As Long
Dim DataOutputArrayRow As Long, SourceArrayRow As Long
Dim SourceArrayColumn As Long
Dim LastRowColumnA As Long, LastRowColumnJ As Long
Dim City As String, State As String, ZipCode As String
Dim DataOutputArray As Variant, SourceDataArray As Variant
'
LastRowColumnA = Range("A" & Rows.Count).End(xlUp).Row ' Get Last used row of Column A
LastRowColumnJ = Range("J" & Rows.Count).End(xlUp).Row ' Get Last used row of Column J
SourceDataArray = Range("A2:E" & LastRowColumnA) ' Save range of data into SourceDataArray
DataOutputArrayRow = 0 ' Initialize DataOutputArrayRow
'
ReDim DataOutputArray(1 To UBound(SourceDataArray), 1 To 4) ' Set the # of rows and columns for DataOutputArray
'
For SourceArrayRow = 1 To UBound(SourceDataArray, 1) ' Loop through the rows of SourceDataArray
For SourceArrayColumn = 1 To UBound(SourceDataArray, 2) ' Loop through the columns of SourceDataArray
If IsNumeric(Left$(Trim(SourceDataArray(SourceArrayRow, SourceArrayColumn)), 1)) Then ' If NumberAddress Found then ...
DataOutputArrayRow = DataOutputArrayRow + 1 ' Increment DataOutputArrayRow
DataOutputArray(DataOutputArrayRow, 1) = WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, _
SourceArrayColumn)) ' Save street address to DataOutputArray
'
If Len(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, SourceArrayColumn + 1))) - _
Len(WorksheetFunction.Substitute(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, _
SourceArrayColumn + 1)), " ", "")) = 1 Then ' If additional data for street addr found then ...
DataOutputArray(DataOutputArrayRow, 1) = DataOutputArray(DataOutputArrayRow, 1) & " " & _
WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, SourceArrayColumn + 1)) ' Append it to the street address
ZipCode = Mid$(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, _
SourceArrayColumn + 2)), InStrRev(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, _
SourceArrayColumn + 2)), " ") + 1) ' Find zip code in next column
State = Mid$(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, SourceArrayColumn + 2)), _
InStrRev(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, SourceArrayColumn + 2)), _
" ") - 2, 2) ' Find state in next column
CityLength = Len(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, _
SourceArrayColumn + 2))) - Len(ZipCode) - Len(State) - 2 ' Calculate length of city in next col
City = Left$(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, _
SourceArrayColumn + 2)), CityLength) ' Get city
Else ' Else
ZipCode = Mid$(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, SourceArrayColumn + 1)), _
InStrRev(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, _
SourceArrayColumn + 1)), " ") + 1) ' Find zip code in next column
State = Mid$(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, _
SourceArrayColumn + 1)), InStrRev(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, _
SourceArrayColumn + 1)), " ") - 2, 2) ' Find state in next column
CityLength = Len(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, _
SourceArrayColumn + 1))) - Len(ZipCode) - Len(State) - 2 ' Calculate length of city in next col
City = Left$(WorksheetFunction.Trim(SourceDataArray(SourceArrayRow, _
SourceArrayColumn + 1)), CityLength) ' Get city
End If
'
DataOutputArray(DataOutputArrayRow, 2) = City ' Save City to DataOutputArray
DataOutputArray(DataOutputArrayRow, 3) = State ' Save State to DataOutputArray
DataOutputArray(DataOutputArrayRow, 4) = ZipCode ' Save ZipCode to DataOutputArray
Exit For
End If
Next
Next
'
Range("G2:J" & LastRowColumnJ).Delete ' Erase any previous results
Range("G2:J" & LastRowColumnA) = DataOutputArray ' Display results
End Sub