簡體   English   中英

從格式為“City, State Zip”的文本中解析“City, State”和“Zip”

[英]Parse “City, State” and “Zip” from text formatted as “City, State Zip”

我需要將“郵編”中的“城市、州”合並到 4,000 多個商店地址的列表中(下面的小樣本)。

我需要做什么才能僅將具有“City,State Zip”的單元格拆分為兩個新列,其中一個具有“City,State”,另一個具有“Zip”,同時忽略所有其他單元格?

Bel Air     
3436 Bel Air Mall       
Mobile, AL 36606
Bridge Street       
330 The Bridge Street       
Huntsville, AL 35806        
Colonial Mall Auburn        
1627 Opelika Road       
Auburn, AL 36830        
Eastchase       
6850 Eastchase Parkway      
Montgomery, AL 36117        
Eastern Shore Centre        
30500 Highway 181       
Spanish Fort, AL 36527      
Gadsden     
1001 Rainbow Drive      
Gadsden, AL 35901       

這里有一些工作代碼。 假設您的地址位於 excel 工作表列“A”中。 並且它們都遵循與您的示例相同的格式

Sub split_out_zip()

For x = 1 To Range("A" & Rows.Count).End(xlUp).Row
Line = trim(Cells(x, "A"))

If InStr(Line, ",") Then
    zip = Right(Line, 5)
    cityState = Left(Line, Len(Line) - 5)
    Cells(x, "B") = cityState
    Cells(x, "C") = zip

End If

Next x
End Sub

這將 output 它在 B 列和 C

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM