我想创建一个自定义函数,它可以接受所选参数并将其内容分割到不同的单元格中。将字符串拆分为多个字符的函数
例如:
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
VBA用户定义函数不能更改其他单元格的值。也许您可以改为使用WorkSheet_Change事件,或者只保留A列中的原始值并在其他列中使用Excel公式来保存单独的字母。作为一个侧面说明,请尝试使用“Mid”功能,而不是“Left”和“Right”。 –