我目前正在尝试将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
最佳Ť
答案 0 :(得分:0)
使用间接:
=ConcatItNoDuplicities(INDIRECT(A1))
答案 1 :(得分:0)