0

I have a piece of code which puts an array formula in a range. It is throwing

runtime error:438 "Object doesn't support this property or method"

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").ArrayFormula  = 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").ArrayFormula = strFormula

NOTE: If I use shtAbsoluteData.Range("D2").Formula then there is no error but the result is incorrect

2 Answers 2

0

You can't enter strings with a length of more than 255 characters directly via vba as like in your case. Please use the Replace-trick for such cases.

Sign up to request clarification or add additional context in comments.

Comments

0

The code shall probably read:

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, """" ,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)))"

it should help if it is Text with empty arguments what makes problem.

PS. Note doubled quotation marks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.