如何将最后三个数字和一个字符串与excel中的其余文本分开

时间:2016-12-29 20:48:18

标签: excel split

我有:

  

第1栏

Here is line one abc 1 3 100
Here is another line jkmr 5-20 230 3
Other line three rjleer 44 10 22

并想把它变成:

enter image description here

到目前为止,我有这个:

=RIGHT(A1,LEN(C1)-FIND("*",SUBSTITUTE(A1," ","*",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-3)))

分隔最后四个字符串。然后我可以在空格上分开它们。但是如何从文本中删除最后四个字符串?

1 个答案:

答案 0 :(得分:1)

这似乎可以为您提供所需的结果:

Sub BreakUp()
    Dim N As Long, i As Long, k As Long, j As Long
    N = Cells(Rows.Count, "A").End(xlUp).Row

    For i = 1 To N
        k = 0
        arr = Split(Cells(i, 1).Value, " ")

        For j = 6 To 3 Step -1
            Cells(i, j).Value = arr(UBound(arr) - k)
            k = k + 1
        Next j

        For j = 0 To UBound(arr) - 4
            Cells(i, 2).Value = Cells(i, 2).Value & " " & arr(j)
        Next j
    Next i
    End Sub