Excel VBA-如何添加动态阵列公式
我正在通过VBA将公式添加到工作表中,该公式应该是:
=UNIQUE(IF(TableA[ColumnA]=A1,TableA[ColumnB],""))
它利用Excel中的新溢出功能为我提供了B列值列表,其中a列中的相关值a列在单元格中。我也应用了。删除任何多个空白(“”)结果的唯一功能。
如果我将公式手动键入Excel,则可以很好地工作,但是在使用VBA添加公式时,Excel在公式中添加 @符号,并使其显示#value!。
用于添加公式的VBA线是:
=Cells(x,y).Formula = "=UNIQUE(IF(TableA[ColumnA]=A1,TableA[ColumnB],""""))"
Excel中的结果输出是:
=@UNIQUE(IF(TableA[@[ColumnA]]=A1,TableA[ColumnB],""))
发生了什么,我错过了什么?
提前致谢!
I am adding a formula to a worksheet via VBA which should be:
=UNIQUE(IF(TableA[ColumnA]=A1,TableA[ColumnB],""))
This utilises the new SPILL feature in Excel to give me a list of column B values where the related value in column A matches what is in cell A. I'm also applying the UNIQUE function to remove any multiple blank ("") results.
This works perfectly if I manually type the formula into Excel, however in using VBA to add the formula, Excel is adding @ symbols within the formula, and causing it to show #VALUE!.
The VBA line being used to add the formula is:
=Cells(x,y).Formula = "=UNIQUE(IF(TableA[ColumnA]=A1,TableA[ColumnB],""""))"
The resulting output in Excel is:
=@UNIQUE(IF(TableA[@[ColumnA]]=A1,TableA[ColumnB],""))
What is going on, and what have I missed?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好问题,我查一下...
简而
代码>而不是
=单元格(x,y).formula
解释:
@称为隐式相交操作员。来自MS文档:
,为什么它会出现在您的较新的excel O365中?好吧,
range.formula
使用IIE(隐式交叉点),从而将@
添加到基本上撤消您的动态数组功能。unique
是一个新的动态数组函数。因此,要在代码中写下此内容,您应该使用range.formula2
属性(或range.formula2r1c1
如果使用r1c1
note法)。这些属性使用AE(数组评估),现在是默认值。这里是来自MS的一位信息文档,该主题解释了
公式
和公式2
之间的区别。如果您想进一步了解隐式交集操作员,请查看 this
我在早些时候与隐式相交的另一个问题回答了另一个问题示例实际工作在这里如果发现它很有趣。
Good question, and I looked it up...
In short:
Use
=Cells(x,y).Formula2
instead of=Cells(x,y).Formula
Explaination:
The
@
that shows is called the implicit intersection operator. From MS docs:But why does it appear in your newer Excel O365? Well,
Range.Formula
uses IIE (implicit intersection) thus adding the@
to basically undo your dynamic array functionality.UNIQUE
is a new dynamic array function. So, to write this out in code, you should use theRange.Formula2
property (orRange.Formula2R1C1
if you useR1C1
notation). These properties use AE (array evaluation) and is now the default.Here is an informative doc from MS on the subject which explains the difference between
Formula
andFormula2
in more detail.If you want to know more about the implicit intersection operator then have a look at this
I answered another question earlier on that involved implicit intersection with an example on how that actually works here if one finds it interesting.