I am trying to insert a formula into a cell using the .FormulaLocal property of .Range("F2") on a spreadsheet. For all the neighbouring cells this works fine, but just for this specific cell i get a 1004 runtime error when the VBA script runs. The very strange thing is that the formula I'm putting into this cell is an EXACT copy of the .FormulaLocal property already set in the cell (becaue I want to reset the cell to the original formula before doing some more operations). So how can it be that a formula that works without any kind of problem when I enter it into the cell , all of a sudden causes a runtime error when VBA does the same?
The Formula to be entered is: "=IF(INDEX(CartonList!$H:$H,MATCH(PolyList!$A2,CartonList!$L:$L,0))>0,INDEX(CartonList!$H:$H,MATCH(PolyList!$A2,CartonList!$L:$L,0)),"")"
Which in FormulaLocal since I have Swedish language pack installed is: "=OM(INDEX(CartonList!$H:$H;PASSA(PolyList!$A2;CartonList!$L:$L;0))>0;INDEX(CartonList!$H:$H;PASSA(PolyList!$A2;CartonList!$L:$L;0));"")"
And the statement in my VBA script causing the runtime error is:
With ThisWorkbook.Sheets("PolyList")
.
. **Other .FormulaLocal statements that do not cause runtime error**
.
.Range("F2").FormulaLocal = "=OM(INDEX(CartonList!$H:$H;PASSA(PolyList!$A2;CartonList!$L:$L;0))>0;INDEX(CartonList!$H:$H;PASSA(PolyList!$A2;CartonList!$L:$L;0));"")"
.
.
.
End With
I have tried setting .Formula and .Formula2 with the non local version of this formula as well, which did not help. The other formulas that don't cause problems also reference the same sheets "PolyList" and "CartonList" without problems. Only thing different with this particular formula is that it contains an IF statement, but should that really matter?