比方说,我有一列填满了名字,每个名字都在一个单元格中。
First_Name_1 Last_Name_1
First_Name_2 Last_Name_2
First_Name_3 Last_Name_4
名字和姓氏用空格分隔。如何使用 Visual Basic 脚本将此列拆分为两列,以便将 First_Name 放在一列中,将 Last_name 放在旁边的一列中?
已经尝试过此代码,但无法使其工作。
objExcel.ActiveSheet.Columns(4).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
提前致谢!