Reputation: 37
I am trying to run the following procedure that entails placing an array formula in a range ("CA2010") on a sheet ("Slate Data").
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.
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.
Upvotes: 1
Views: 54
Reputation: 34035
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. If you use absolute references, the formula is short enough to be entered using 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.
Upvotes: 1