下面将转换一列中的长列表。如果您只有一个单元格的联系信息,最好手动完成。
Option Explicit
Sub gatherAddress()
Dim i As Long, var As Variant, tmp As Variant
With Worksheets("sheet2")
'put the new header labels in the top row
.Cells(1, "B").Resize(1, 4) = Array("Address", "City", "State", "Zip")
'collect the values from column A
var = .Range(.Cells(2, "A"), .Cells(.Rows.Count, "A").End(xlUp)).Value2
'make room for processed values
ReDim Preserve var(LBound(var, 1) To UBound(var, 1), _
LBound(var, 2) To UBound(var, 2) + 4)
'process the address into separate cells
For i = LBound(var, 1) To UBound(var, 1)
'split the billing address on the linefeed
tmp = Split(var(i, 1), vbLf)
'strip address line
var(i, 2) = tmp(1)
'strip city
var(i, 3) = Split(tmp(2), Chr(44))(0)
'strip city and zip
var(i, 4) = Split(tmp(2), Chr(44))(1)
'strip zip/zip+4 code
var(i, 5) = Split(var(i, 4), Chr(32))(UBound(Split(var(i, 4), Chr(32))))
'remove zip from city
var(i, 4) = Trim(Replace(var(i, 4), var(i, 5), vbNullString))
Next i
'put the processed values back into the worksheet
.Cells(2, "A").Resize(UBound(var, 1), UBound(var, 2)) = var
End With
End Sub