从UDF返回一个Range不是数组

我已经创build了一个UDF,它将各种值,范围和数组input合并到一个数组中。 数组公式

点击ctrl shift input它作为一个数组公式,意味着VALUE(F4:G4)返回一个数组{1,#VALUE} 。 我的公式拼接值(5,“cat”),范围(“F6”,“B2:D6”),甚至像Value()返回的数组,并输出一个数组。 在图像的例子是

 {0.283982519688569,0.161633595994901,0.521865473646119,0.675542592903341,0.119984734979722,0.842918190377968,0.882045093468071,0.57708164295789,0.305844376489788,0.365360349735221,0.131686453379672,0.557018723742854,0.511032693705543,0.746174410924489,0.863516943921978,5,"cat","Dog",1,#VALUE!} 

代码如下:

 Public Function PROBABLY(ParamArray inputArray() As Variant) As Variant 'Takes a list of parameters, the first of which is an integer, and Dim inElement As Variant Dim outputArray() As Variant Dim subcell As Variant 'convert ranges to values 'creating a new array from the mixture of ranges and values in the input array ReDim outputArray(0) For Each inElement In inputArray 'Normal values get copied from the input UDF to an output array, ranges get split up then appended If TypeName(inElement) = "Range" Or TypeName(inElement) = "Variant()" Then For Each subcell In inElement outputArray(UBound(outputArray)) = subcell ReDim Preserve outputArray(UBound(outputArray) + 1) Next subcell 'Stick the element on the end of an output array Else outputArray(UBound(outputArray)) = inElement ReDim Preserve outputArray(UBound(outputArray) + 1) End If Next inElement ReDim Preserve outputArray(UBound(outputArray) - 1) PROBABLY = outputArray End Function 

这只是为了显示公式的多样性与各种投入,实际上我不想在数组公式中使用这个。 =PROBABLY(B2:D6,5,"cat")可以正常input, 不用按 Ctrl键 进入 。 但问题是,这返回一个Variant() – 特别是一个数组*,这使得它很难用于非数组公式,这往往需要一个Rangeinput。 所以=CONCAT(PROBABLY(B2:D6,5))工作正常,但SUMIF(PROBABLY(B2:D6,5),">.5")不起作用,因为SUMIF()需要范围input。 相同的原因SUMIF(VALUE(1,2),">.5")不起作用,就像我的函数,值返回一个数组。

所以问题 :我可以诱使 Excel认为我的数组是一个范围,以某种方式将其格式化为一个范围。 很明显,我可以将代码从UDF中移出,然后粘贴到一个临时的电子表格区域,然后告诉excel引用它,但是我希望保留UDF包装器。 (我不认为我可以在UDF中编辑工作表,虽然有一些隐藏的空间,我可以粘贴数组并从公式中访问它?

大声思考,有什么更好的见解?

*因此()Variant之后