【发布时间】:2017-12-01 03:38:29
【问题描述】:
我目前正在尝试将单元格的内容作为参数传递给 excel 中的用户定义函数。
也就是说,我计算了我对单元格感兴趣的范围,在那里我得到了类似“sheet1!X17:X37”的内容。
现在我想将此单元格(例如 A1)传递给 udf。例如,我希望在 B1 中使用“=myfunction(A1)”而不是“=myfunction(sheet1!X17:X37)。
有什么想法吗?
我的功能是这样的:
Public Function ConcatItNoDuplicities(ByVal cellsToConcat As Range) As String
ConcatItNoDuplicities = ""
If cellsToConcat Is Nothing Then Exit Function
Dim oneCell As Range
Dim result As String
For Each oneCell In cellsToConcat.Cells
Dim cellValue As String
cellValue = Trim(oneCell.Value)
If cellValue <> "" Then
If InStr(1, result, cellValue, vbTextCompare) = 0 Then _
result = result & cellValue & ","
End If
Next oneCell
If Len(result) > 0 Then _
result = Left(result, Len(result) - 1)
ConcatItNoDuplicities = result
End Function
最好的 T
【问题讨论】:
-
嗯...也许我遗漏了一些东西,但是一个单元格的串联就是那个单元格,不是吗?所以这和
=A1不一样 -
实际上 A1 包含我想要连接的范围,我想在我的函数中使用 A1 的内容作为参数,而不是连接 A1。
标签: excel vba user-defined-functions