1
votes

I'm trying to automatically fill a range with formulaR1C1 and a = IF() i recorded before, but I keep getting a 1004 error. I have this loop running several time in this particular sub, and it works well for every other formula, but with the = IF() it doesn't work...

The line rcell1.FormulaR1C1 = "=IF(RC[-1]>0;RC[-1];0)"is highlighted.

Set subgain = Range(Cells(i - period - 1, 16), Cells(i + j, 16))
With subgain
For Each rcell1 In subgain
       rcell1.FormulaR1C1 = "=IF(RC[-1]>0;RC[-1];0)"
Next rcell1
End With

Any idea pliz?

1

1 Answers

2
votes

There's a syntax error in your formula, you're using ; as delimiter but it should be instead ,. Replace this:

rcell1.FormulaR1C1 = "=IF(RC[-1]>0;RC[-1];0)

with this:

rcell1.FormulaR1C1 = "=IF(RC[-1]>0,RC[-1],0)"

and it should work fine.