如果你不介意一些 VBA,你可以试试这个:
数据的基本问题是字段中包含的日期是可变长度的,并且在这些元素中包含唯一真正的分隔符(空格)。使用右侧的空格,可用于返回您的字段。
感谢 Sumit Bansal 在 (https://trumpexcel.com) 的原始 LastPosition() 函数。但是,此函数只返回最后一次出现的字符。
但稍作修改后,LastPositionN() 现在返回搜索文本的第 n 次出现,指定为第三个参数。
注意:点击此处查看原始功能,以及剪切/粘贴到 VBA 编辑器的信息:https://trumpexcel.com/find-characters-last-position/
Function LastPosition(rCell As Range, rChar As String)
'This function gives the last nth position of the specified character
'This code has been developed by Sumit Bansal (https://trumpexcel.com)
Dim rLen As Integer
rLen = Len(rCell)
For i = rLen To 1 Step -1
If Mid(rCell, i - 1, 1) = rChar Then
'LastPosition = i ' original code returnd Last position +1
LastPosition = i - 1 ' correction returns codes original intent
Exit Function
End If
Next i
End Function
Function LastPositionN(rCell As Range, rChar As String, Optional nNthOccurance As Integer = 1)
'This function gives the last position of the specified character
'This code has been developed by Sumit Bansal
' (https://trumpexcel.com)
' and was modified my Jeff Bowman 9/11/2018 for nth position from right
'Returns zero (0) if not nth occurence is not found
Dim rLen As Integer, nNthCount As Integer, LastPosition As Integer
nNthCount = 0
rLen = Len(rCell)
For i = rLen To 1 Step -1
If Mid(rCell, i - 1, 1) = rChar Then
'LastPosition = i ' original code returnd Last position +1
LastPositionN = i - 1 ' correction returns codes original
'intent
nNthCount = nNthCount + 1
If nNthCount = nNthOccurance Then
Exit Function
End If
End If
Next i
End Function
`
现在,通过 left()、right() 和 find(),我们可以隔离并解析数据字符串的结尾。
=LEFT(RIGHT(A8,LastPositionN(A8," ",1)),FIND(" ",RIGHT(A8,LastPositionN(A8," ",1))))