简体   繁体   English

FormulaArray 产生运行时 1004 错误

[英]FormulaArray Producing Runtime 1004 Error

I am trying to run the following procedure that entails placing an array formula in a range ("CA2010") on a sheet ("Slate Data").我正在尝试运行以下过程,该过程需要在工作表(“Slate Data”)上的范围(“CA2010”)中放置一个数组公式。

I've tested the the array formula many times and it produces the desired results.我已经多次测试了数组公式,它产生了想要的结果。

The sub below gets下面的子得到

run-time '1004' error: Unable to set the FormulaArray property of the Range class.运行时“1004”错误:无法设置 Range 类的 FormulaArray 属性。

Sub countuniqueBINs()

Dim placementoutlook As Workbook
Set placementoutlook = Excel.Workbooks("Placement Outlook")
Dim sdws As Worksheet
Set sdws = placementoutlook.Sheets("Slate Data")

sdws.Range("CA2010").NumberFormat = "general"
sdws.Range("CA2010").FormulaArray = "=SUM(IF(FREQUENCY(IF(SUBTOTAL(3,OFFSET(E2:E2000,ROW(E2:E2000)-ROW(E2),0,1)),MATCH(""~""&E2:E2000,E2:E2000&"""",0)),ROW(E2:E2000)-ROW(E2)+1),1))"

End Sub

I tried breaking the array formula into two parts based on some guidance out there, but it still did not resolve the issue.我尝试根据一些指导将数组公式分成两部分,但它仍然没有解决问题。

The reason for the error is that the R1C1 format version of your formula exceeds 255 characters (even though the A1 style version is much shorter than that) due to the relative references.错误的原因是由于相对引用,您的公式的R1C1格式版本超过了 255 个字符(即使A1样式版本比此短得多)。 If you use absolute references, the formula is short enough to be entered using FormulaArray ;如果使用绝对引用,则公式足够短,可以使用FormulaArray输入; if you can't do that, you'll need to use the workaround of splitting the formula into sections so that you can use the Range.Replace method after entering a shorter version.如果您不能这样做,则需要使用将公式拆分为多个部分的解决方法,以便您可以在输入较短版本后使用Range.Replace方法。

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

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