I have a piece of code which puts an array formula in a range. It is throwing runtime error:1004 "Unable to set the FormulaArray property of the Range class". But when I paste the same formula in the cell and hit Ctrl+Shift+Enter everything works fine.
strFormula = "=IF(SUM(--(A2=Data!$A$2:$A$1423)*--(B2=YEAR(Data!$B$2:$B$1423))* --(C2=MONTH(Data!$B$2:$B$1423)) * (Data!$E$2:$E$1423))=0,TEXT(,),SUM(--(A2=Data!$A$2:$A$1423)*--(B2=YEAR(Data!$B$2:$B$1423))* --(C2=MONTH(Data!$B$2:$B$1423)) * (Data!$E$2:$E$1423)))"
shtAbsoluteData.Range("D2").FormulaArray = strFormula
The problem occurs when the IF condition was inserted. So without the IF the following code works fine:
strFormula = "=SUM(--(A2=Data!$A$2:$A$1423)*--(B2=YEAR(Data!$B$2:$B$1423))* --(C2=MONTH(Data!$B$2:$B$1423)) * (Data!$E$2:$E$1423))"
shtAbsoluteData.Range("D2").FormulaArray = strFormula
Note: If I use shtAbsoluteData.Range("D2").Formula then there is no error but the result is incorrect