当从Excel VBA UDF调用时,Range.Precedants返回范围而不是其先例。有解决方法吗? [英] When called from an Excel VBA UDF, Range.Precedents returns the range and not its precedents. Is there a workaround?
问题描述
我有这个VBA功能:
公共函数testPrec(目标为范围)As String
testPrec = target .Precedents.Address(External:= False)
结束函数
在单元格C11中,I有这个公式:
= C6 + C8
如果我从即时窗口调用 testPrec
,它工作得很好:
pre code code $ c $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ b
编辑:如果从非UDF宏Sub调用,它也可以正常工作。这个异常是UDF的情况。
如果我把它从工作表中称为UDF:
= testPrec(C11)
我刚刚收回$ C $ 11有没有人知道发生了什么,甚至更好的如何从UDF调用中获取实际的先例?
(我正在使用Excel 2007。)
我想到的唯一解决方法是获取target.formula并解析它 - 不是很好。
I have this VBA function:
Public Function testPrec(target As Range) As String
testPrec = target.Precedents.Address(External:=False)
End Function
In cell C11, I have this formula:
=C6+C8
If I call testPrec
from the immediate window, it works just fine:
?testPrec([c11])
$C$6,$C$8
EDIT: It also works fine if called from a non-UDF macro Sub. The anomaly is the UDF case.
If I call it from the worksheet as a UDF:
=testPrec(C11)
I just get back "$C$11".
Does anyone know what's going on, or even better how to get the actual precedents from within a UDF call? (I'm using Excel 2007.)
The only workaround I can think of is to get target.formula and parse it - not very nice.
这篇关于当从Excel VBA UDF调用时,Range.Precedants返回范围而不是其先例。有解决方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!