[英]excel pass cell content to udf as range argument
我目前正在尝试将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
间接使用:
=ConcatItNoDuplicities(INDIRECT(A1))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.