将字符串分割成多个字符的函数

1 excel vba

我想创建一个自定义函数,它接受选定的参数并将其内容拆分到不同的单元格上。

例子 :

A1=ABCDE

变成

B1=A, C1=B, D1=C, E1=D, F1=E

这就是我尝试过的:

Function SplitWord(Word)
NbCar = Len(Word) // get the number of cardinals of the text
SplitWord = Left(Word, 1) // put the first letter in the cell that called the function
t = NbCar - 1
For i = 1 To t
ActiveCell.Offset(0, i) = Right(Left(Word, i), 1)
Next
End Function
Run Code Online (Sandbox Code Playgroud)

小智 5

  1. 在单元格 A1 中输入要拆分的内容。
  2. 将其粘贴到单元格 B1 中:=MID($A$1,COLUMN()-COLUMN($B$1)+1,1)
  3. 向右拖动