简体   繁体   English

字符数少于255时的VBA FormulaArray范围类错误

[英]VBA FormulaArray range class error when the Characters are less than 255

The VBA .FormulaArray seems to have a problem with my range. VBA .FormulaArray似乎与我的范围有关。 I've read that it can't handle over 255 characters, but mine is only about 108, but I could be understanding it wrong. 我读过它不能处理255个以上的字符,但是我的字符大约只有108个,但是我可能理解错了。

It gives an 它给出了

Error 1004: 错误1004:
Unable to set FormulaArray property of the Range class. 无法设置Range类的FormulaArray属性。

I've tried leaving the formula in the table column and let it automatically populate when the table is filled with the Macro, but the problem is that the Index array table doesn't exist yet before the Macro starts running. 我尝试将公式保留在表列中,并在表中填充宏后自动填充该公式,但是问题是在宏开始运行之前索引数组表尚不存在。

Also tried leaving it as text and then changing the column to "general" but it doesn't work. 还尝试将其保留为文本,然后将列更改为“常规”,但是它不起作用。 And I know it will create a problem changing it to an array formula this way as well. 而且我知道它也会以这种方式将其更改为数组公式会产生问题。

This is the code I'm using: 这是我正在使用的代码:

With wsOutdated.ListObjects("Table_Outdated_Stock_Counts")
        .ListColumns("Ranging").DataBodyRange.NumberFormat = "General"
        .ListColumns("Ranging").DataBodyRange.FormulaArray = "=INDEX(Table_DispoData[[Class]],MATCH([@Article]&[@Site],Table_DispoData[Article]&Table_DispoData[Site],0),1)"
    End With

I need the table column to populate automatically with the array formula. 我需要表列自动用数组公式填充。 It works for other columns(they are not array formulas though and only need to match a single value). 它适用于其他列(尽管它们不是数组公式,只需要匹配一个值)。

Maybe you could try: 也许您可以尝试:

.ListColumns("Ranging").DataBodyRange.Cells(1, 1).FormulaArray = "=INDEX(Table_DispoData[[Class]],MATCH([@Article]&[@Site],Table_DispoData[Article]&Table_DispoData[Site],0),1)"

Instead of : 代替 :

.ListColumns("Ranging").DataBodyRange.FormulaArray = "=INDEX(Table_DispoData[[Class]],MATCH([@Article]&[@Site],Table_DispoData[Article]&Table_DispoData[Site],0),1)"

and see if it works for you! 看看它是否对您有用!

Explanation: 说明:

Your code is trying to write Array formula to multiple cells simultaneously which is not allowed. 您的代码尝试将Array公式同时写入多个单元格,这是不允许的。 If you try to do this in Excel then it will return an error "Multi-cell array formulas aren't allowed in tables". 如果尝试在Excel中执行此操作,则它将返回错误“表中不允许使用多单元格数组公式”。

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

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