在 Excel 中,我有一列名称格式为“FirstName LastName”的名称。我想将整列分成两列,一列包含所有名字,另一列包含所有姓氏。
到目前为止我的代码:
'Splitting the Traveler Display Name column
Dim SplitPoint As Long
'L2 is the column containing names to be split
Range("L2").Select
Do Until IsEmpty(ActiveCell)
'Search for position of space within the cell
SplitPoint = InStrRev(ActiveCell, " ", -1, vbTextCompare)
'Put the last name in the column next to the source column
ActiveCell.Offset(0, 1) = Trim(Left(ActiveCell, SplitPoint))
'Replace the source column with the first name
ActiveCell.Offset(0, 0) = Trim(Mid(ActiveCell, SplitPoint))
Loop
到目前为止,我发现的解决方案要求手动选择单元格,这对于我正在处理的数据量来说是不合理的。我找到了这个解决方案,但我收到以下错误:Invalid Procedure call or argument。