0

I'm trying to fill an Excel 2010 cell programatically via COM Interop, with a string that represents an IF-formula.

The following line of code works just fine, it resolves to value 4 in Excel:

 .Range("C10").Value = "=2+2"

but when I pass an IF-Formula (as String)...

 .Range("C11").Value = "=IF(1+1=2;2;0)"

...I run into a COMException, saying: Exception from HRESULT: 0x800A03EC.

If I enter the same IF-formula directly in Excel, it is parsed correctly.

Thanks for your help!

Chris

blackpanther
  • 10,998
  • 11
  • 48
  • 78

1 Answers1

3

You should replace the semicolons with commas and use .Formula instead .Value

.Range("C11").Formula= "=IF(1+1=2,2,0)"
Dmitry Pavliv
  • 35,333
  • 13
  • 79
  • 80
  • without more information, it's likely that the semicolons are there due to locality preferences, since the OP says the formula works when typed into the cell. +1 for the `.Formula` update – guitarthrower Jan 08 '14 at 19:23