通过 VBA 插入数组公式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27604084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:14:29  来源:igfitidea点击:

Insert an Array Formula via VBA

excelvbaexcel-vbaexcel-formulaarray-formulas

提问by Bramat

I'm using VBA, and I need to insert an array formula (the one that if I'm writing it manually, I'll press Ctrl+Shift+Enterand not just Enter). When I'm inserting it like a regular formula it doesn't work, neither when I put it with {} around it... What's the correct way of writing that formula using VBA?

我使用VBA,我需要插入数组公式(一,如果我手工编写的话,我会按Ctrl+ Shift+Enter不只是Enter)。当我像常规公式一样插入它时,它不起作用,当我将它与 {} 放在一起时也不起作用......使用 VBA 编写该公式的正确方法是什么?

The formula is this:

公式是这样的:

 =INDEX(subset!R1C1:R2472C10,MATCH(1,(RC1=subset!C1)*(RC2=subset!C2)*(RC5=subset!C5)*(RC6=subset!C6),0),10)  

回答by Gareth

You're looking for the FormulaArrayproperty that you can set for a cell like so:

您正在寻找FormulaArray可以为单元格设置的属性,如下所示:

Range("A1").FormulaArray = "=INDEX(subset!R1C1:R2472C10,MATCH(1,(RC1=subset!C1)(RC2=subset!C2)(RC5=subset!C5)*(RC6=subset!C6),0),10)"

See the documentation here: http://msdn.microsoft.com/en-us/library/office/ff837104%28v=office.15%29.aspx

请参阅此处的文档:http: //msdn.microsoft.com/en-us/library/office/ff837104%28v=office.15%29.aspx