要实现此目的,您将需要纯 VBA。创建一个自定义函数以在 1 个单元格中获取所需的字符串。然后,如果需要,稍后可以使用“文本分列”。
我的功能:
Public Function GET_STRING(ByVal ThisCell As Range) As String
Dim i As Integer
Dim MyPositions As String
Dim ArrPositions As Variant
For i = 2 To Len(ThisCell.Value) Step 1
If Mid(ThisCell.Value, i, 1) = UCase(Mid(ThisCell.Value, i, 1)) And _
Mid(ThisCell.Value, i, 1) <> " " And Left(Mid(ThisCell.Value, i - 1, 1), 1) <> " " Then MyPositions = MyPositions & i & ";"
Next i
ArrPositions = Split(Left(MyPositions, Len(MyPositions) - 1), ";")
For i = 0 To UBound(ArrPositions) Step 1
If i = 0 Then
GET_STRING = Left(ThisCell.Value, ArrPositions(i) - 1) & "," & Mid(ThisCell.Value, ArrPositions(i), ArrPositions(i + 1) - ArrPositions(i))
ElseIf i <> UBound(ArrPositions) Then
GET_STRING = GET_STRING & "," & Mid(ThisCell.Value, ArrPositions(i), ArrPositions(i + 1) - ArrPositions(i))
Else
GET_STRING = GET_STRING & "," & Mid(ThisCell.Value, ArrPositions(i), Len(ThisCell.Value) - ArrPositions(i) + 1)
End If
Next i
End Function
当我在 Excel 上使用它时我得到什么