Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 解析";“城市、州”;及;Zip";来自格式为“的文本”;城市、州邮政编码“;_Excel_Vba_Excel Formula - Fatal编程技术网

Excel 解析";“城市、州”;及;Zip";来自格式为“的文本”;城市、州邮政编码“;

Excel 解析";“城市、州”;及;Zip";来自格式为“的文本”;城市、州邮政编码“;,excel,vba,excel-formula,Excel,Vba,Excel Formula,我需要将“Zip”中的“城市、州”合并到4000多个门店地址的列表中(下面的小示例) 我需要做什么才能只将包含“City,State Zip”的单元格拆分为两个新列,其中一列包含“City,State”,另一列包含“Zip”,而忽略所有其他单元格 Bel Air 3436 Bel Air Mall Mobile, AL 36606 Bridge Street 330 The Bridge Street Huntsville, AL 35806

我需要将“Zip”中的“城市、州”合并到4000多个门店地址的列表中(下面的小示例)

我需要做什么才能只将包含“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

这将在B列和C列中输出它

查找以5位数字结尾的行。然后在最后一个空格上拆分这些线。如果遇到问题,请返回公式或代码。我建议通过
CreateObject(“vbscript.regexp”)
使用正则表达式,如果Trim(cellValue)像“*####”,那么
感谢所有帮助和建议!这太不可思议了,谢谢你,乔希!节省大量时间。