我正在创建一个VBA函数,用于将单元格与逗号分隔符合并,并尝试将其保存到我的个人笔记本中,以便所有笔记本都可以使用它。出于某种原因,当我使用“记录宏”功能时,我可以使它工作,但是当我使用VBA时则不能。
VBA:
Function combine(WorkRng As Range, Optional Sign As String = ",") As String
'Update 20130815
Dim Rng As Range
Dim OutStr As String
For Each Rng In WorkRng
If Rng.Text <> "," Then
OutStr = OutStr & Rng.Text & Sign
End If
Next
combine = Left(OutStr, Len(OutStr) - 1)
End Function
...以下是显示保存位置的屏幕截图:
但是当我输入=combine(CELL_RANGE_GOES_HERE)
时,会产生#NAME?
。我做错了什么?