简体   繁体   English

VBA使用VBA插入数组公式?

[英]vba insert array formula using vba?

I am trying to insert an array formula into a cell in excel, however I get an error, "unable to set the formula array for the range class" 我试图将数组公式插入excel中的单元格,但是出现错误,“无法为范围类设置公式数组”

Can someone please show me what I am doing wrong here? 有人可以告诉我我在做什么错吗? Thanks. 谢谢。

intRow4 As Integer, _

intRow4 = excWks4.UsedRange.Rows.Count + 1

lastcell = excWks4.Cells(intRow4, 4).Address

theform = "=IF(ISERROR(INDEX('Look Up Supplier Sheet'!$A$1:$G$10004,SMALL(IF(LEFT('Look Up Supplier Sheet'!$B$1:$B$10004,5)=LEFT(" & lastcell & ",5),ROW($B$1:$B$10004)),ROW(1:1)),6)),"""",INDEX('Look Up Supplier Sheet'!$A$1:$G$10004,SMALL(IF(LEFT('Look Up Supplier Sheet'!$B$1:$B$10004,5)=LEFT(" & lastcell & ",5),ROW($B$1:$B$10004)),ROW(1:1)),6))"

excWks4.Cells(intRow4, 5).FormulaArray = theform

From MSDN - MSDN-

If you use this property to enter an array formula, the formula must use the R1C1 reference style, not the A1 reference style 如果使用此属性输入数组公式,则该公式必须使用R1C1参考样式,而不是A1参考样式

So you need to replace $A$1 with $R1$C1 etc. 因此,您需要将$A$1替换$A$1 $R1$C1等。

FormulaArray has a 255 character limit . FormulaArray字符数上限255个 Yours is at least 309 characters, depending on the length of lastcell . 您的字符数至少为309个字符,具体取决于lastcell的长度。

You could get under 256 characters by shortening your worksheet name. 通过缩短工作表名称,您可以得到少于256个字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM