【发布时间】:2014-02-08 22:17:00
【问题描述】:
我想创建一个自定义函数,该函数采用选定的参数并将其内容拆分到不同的单元格上。
例子:
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。