在Excel中分割地址字段

我有一个地址单元格的Excel文件。

3个不同的数据示例:

123 Main Street/n Apartment2 /n New York, NY 10001 123 Main Street/n New York, NY 10001 123 Main Street 

我想分成三个独立的领域。 但是,正如上面的数据所显示的,有些将会出现0次/ n,有些将会出现2次。 有的会发生3次。

(E6,SEARCH(“/ n”,E6,1)-2)= RIGHT(导出!E6,LEN(导出!E6) – SEARCH(“/ n”,导出! E6,1)-1)

但是,我的公式开始打破,当有可变数量的/ n

有什么build议么?

解决scheme值得回答:

将“/ n”replace为不在数据中的任何单个字符,例如@#$^~ – 并使用Text to Columns

全部replace通过按CTRL + H可用。

如果您不确定angular色是否在您的数据中 – 请在replace前通过search进行检查。

这是使用VBA的另一种方法

 Option Explicit Sub Sample() Dim MyArray() As String Dim ws As Worksheet Dim lRow As Long, i As Long, j As Long, c As Long '~~> Change this to the relevant sheet name Set ws = ThisWorkbook.Sheets("Sheet1") With ws lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If InStr(1, .Range("A" & i).Value, "/n", vbTextCompare) Then MyArray = Split(.Range("A" & i).Value, "/n") c = 1 For j = 0 To UBound(MyArray) .Cells(i, c).Value = MyArray(j) c = c + 1 Next j End If Next i End With End Sub 

SCREENSHOT(之前)

在这里输入图像说明

SCREENSHOT(之后)

在这里输入图像说明