运行时错误1004在vba中复制长数组公式 [英] Runtime Error 1004 Copy long array formula in vba

查看:385
本文介绍了运行时错误1004在vba中复制长数组公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  = {IF(COUNT(IF(ISNUMBER (A30:A1000); IF(C30:C1000> A30:A1000-1; A30:A1000)))> = COUNT(IF(ISNUMBER(A30:A1000); IF(B30:B1000> A30:A1000-1; A30:A1000))); COUNT(IF(ISNUMBER(A30:A1000); IF(C30:C1000> A30:A1000-1; A30:A1000))); IF(COUNT(IF(ISNUMBER(A30:A1000); IF(C30:C1000> A30:A1000-1; A30:A1000)))≤= COUNT(IF(ISNUMBER(A30:A1000); IF(B30:B1000> A30:A1000-1; A30:A1000))) ; COUNT(IF(ISNUMBER(A30:A1000); IF(B30:B1000> A30:A1000-1; A30:A1000))); COUNT(IF(ISNUMBER(A30:A1000); IF(C30:C1000> A30: A1000-1; A30:A1000)))))}} 

现在我想使用以下VBA将代码复制到单元格A2中的代码:

  Sheets(Sheet1)。Range(A2)。FormulaArray = Sheets (Sheet1)范围(B2)。公式

但是,当我使用此代码我得到运行时错误1004。



你有什么想法如何解决这个问题?

解决方案

传递数组时的字符数限制为255 ...



https://support.microsoft.com/en-us/kb/213181



设置A30的命名范围:B30的A1000,B的B1000,D的c30:c1000(C被保留,所以你不能使用它,CC也会使这个公式太长)(ctrl + f3打开命名范围管理器,然后点击新按钮)



然后更改您的公式以使用命名范围。


$ b $ (IF(IS(A),IF(D> A-1,A)))> = COUNT(IF(ISNUMBER(A))IF(B& A-1,A))),COUNT(IF(ISNUMBER(A),IF(D>一种-1,A))),IF(COUNT(IF(ISNUMBER(A),IF(D>一种-1, A)))≤= COUNT(IF(ISNUMBER(A),IF(B>一种-1,A))),COUNT(IF(ISNUMBER(A),IF(B>一种-1,A))) ,COUNT(IF(ISNUMBER(A),IF(D> A-1,A)))))



自定义VBA功能,可以让您用更短的字符替换if语句中的重复代码字符串将带你到255以下。但最终你需要达到255以下。一旦在255以下,你的代码可以正常工作,无论是上面的改变还是使用较短的数组公式。 (请注意,我将分号更改为逗号,因此如果使用分号,则可能需要更改它们)


I have the following array formula in cell B2 in my Excel spreadsheet:

={IF(COUNT(IF(ISNUMBER(A30:A1000);IF(C30:C1000>A30:A1000-1;A30:A1000)))>=COUNT(IF(ISNUMBER(A30:A1000);IF(B30:B1000>A30:A1000-1;A30:A1000)));COUNT(IF(ISNUMBER(A30:A1000);IF(C30:C1000>A30:A1000-1;A30:A1000)));IF(COUNT(IF(ISNUMBER(A30:A1000);IF(C30:C1000>A30:A1000-1;A30:A1000)))<=COUNT(IF(ISNUMBER(A30:A1000);IF(B30:B1000>A30:A1000-1;A30:A1000)));COUNT(IF(ISNUMBER(A30:A1000);IF(B30:B1000>A30:A1000-1;A30:A1000)));COUNT(IF(ISNUMBER(A30:A1000);IF(C30:C1000>A30:A1000-1;A30:A1000)))))}

Now I want to use the following VBA code to copy this code into cell A2:

Sheets("Sheet1").Range("A2").FormulaArray = Sheets("Sheet1").Range("B2").Formula

However, when I use this code I get runtime error 1004.

Do you have any idea how to solve this issue?

解决方案

character limit of 255 when passing arrays...

https://support.microsoft.com/en-us/kb/213181

Set up named ranges for a30:A1000 of A, B30:B1000 of B, and c30:c1000 of D (C is reserved so you can't use it and CC will make this formula too long also) (ctrl+f3 to open the named range manager and then hit new button)

Then Change your formula to use the named ranges.

=IF(COUNT(IF(ISNUMBER(A),IF(D>A-1,A)))>=COUNT(IF(ISNUMBER(A),IF(B>A-1,A))),COUNT(IF(ISNUMBER(A),IF(D>A-1,A))),IF(COUNT(IF(ISNUMBER(A),IF(D>A-1,A)))<=COUNT(IF(ISNUMBER(A),IF(B>A-1,A))),COUNT(IF(ISNUMBER(A),IF(B>A-1,A))),COUNT(IF(ISNUMBER(A),IF(D>A-1,A)))))

Alternately you could set up custom VBA functions that would allow you to replace the repetitive code within your if statement with shorter strings of characters to bring you under the 255. But ultimately you need to get under 255. Once under 255 your code works fine, either with my changes above or with a shorter array formula. (note that I changed the semi-colons to commas so you might need to change them back if you use semi-colons)

这篇关于运行时错误1004在vba中复制长数组公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆